Click here to Skip to main content
15,883,901 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: how to make discussion and comments in asp.net C# MVC 2.0 ? Pin
Boipelo5-Aug-13 4:27
Boipelo5-Aug-13 4:27 
Questiongridview inside gridview with update delete Pin
vipulparmar904-Aug-13 22:46
vipulparmar904-Aug-13 22:46 
AnswerRe: gridview inside gridview with update delete Pin
Boipelo5-Aug-13 4:22
Boipelo5-Aug-13 4:22 
AnswerRe: gridview inside gridview with update delete Pin
Dholakiya Ankit7-Aug-13 20:01
Dholakiya Ankit7-Aug-13 20:01 
GeneralRe: gridview inside gridview with update delete Pin
vipulparmar907-Aug-13 22:10
vipulparmar907-Aug-13 22:10 
GeneralRe: gridview inside gridview with update delete Pin
vipulparmar9028-Aug-13 19:27
vipulparmar9028-Aug-13 19:27 
GeneralRe: gridview inside gridview with update delete Pin
Dholakiya Ankit28-Aug-13 19:57
Dholakiya Ankit28-Aug-13 19:57 
GeneralRe: gridview inside gridview with update delete Pin
vipulparmar9028-Aug-13 22:00
vipulparmar9028-Aug-13 22:00 
aspx page is :

XML
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="#f1f1f1" 
                                    AutoGenerateColumns=false DataSourceID="SqlDataSource1" DataKeyNames="ShowTimeId" 
                                    GridLines=None OnRowDataBound="GridView1_RowDataBound" 
                                    OnRowCommand = "GridView1_RowCommand" OnRowUpdating = "GridView1_RowUpdating" BorderStyle=Outset
                                    OnRowDeleting = "GridView1_RowDeleting" OnRowDeleted = "GridView1_RowDeleted"
                                    OnRowUpdated = "GridView1_RowUpdated" AllowSorting=true ShowFooter=true
                                    Width="100%" >
                                    <RowStyle BackColor="Gainsboro" />
                                    <AlternatingRowStyle BackColor="White" />
                                    <HeaderStyle BackColor="#0083C1" ForeColor="White"/>
                                    <FooterStyle BackColor="White" />
                                    <Columns>
                                        <asp:TemplateField>
                                            <ItemTemplate>
                                                <a href="javascript:expandcollapse('div<%# Eval("ShowTimeId") %>', 'one');">
                     <img id="imgdiv<%# Eval("ShowTimeId") %>" alt="Click to show/hide Orders for Customer <%# Eval("ShowTimeId") %>"  width="9px" border="0" src="../images/plus.gif"/>
                 </a>
             </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="ShowTime Id" SortExpression="ShowTimeId">
             <ItemTemplate>
                 <asp:Label ID="lblShowTimeId" Text='<%# Eval("ShowTimeId") %>' runat="server"></asp:Label>
             </ItemTemplate>
             <EditItemTemplate>
                 <asp:Label ID="lblShowTimeId" Text='<%# Eval("ShowTimeId") %>' runat="server"></asp:Label>
             </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Theatre Id" SortExpression="TheatreId">
             <ItemTemplate>
                 <asp:Label ID="lblTheatreId" Text='<%# Eval("TheatreId") %>' runat="server"></asp:Label>
             </ItemTemplate>
             <EditItemTemplate>
                 <asp:Label ID="lblTheatreId" Text='<%# Eval("TheatreId") %>' runat="server"></asp:Label>
             </EditItemTemplate>
             <FooterTemplate>
                 <asp:DropDownList ID="ddlTheatre" runat="server" CssClass="form_input" AutoPostBack="True" TabIndex="1"
                     DataSourceID="SqlDataSource2" DataTextField="TheatreName" DataValueField="TheatreID" Width="130px"
                     SelectedValue='<%# Bind("TheaterName") %>'>
                 </asp:DropDownList>
             </FooterTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Movie Id" SortExpression="MovieId">
             <ItemTemplate>
                 <asp:Label ID="lblMovieId" Text='<%# Eval("MovieName") %>' runat="server"></asp:Label>
             </ItemTemplate>
             <EditItemTemplate>
                 <asp:DropDownList ID="ddlmovie" runat="server" CssClass="form_input" TabIndex="2" Width="130px">
                 </asp:DropDownList>
             </EditItemTemplate>
             <FooterTemplate>
                 <asp:DropDownList ID="ddlMovie" runat="server" CssClass="form_input" TabIndex="2" Width="130px">
                 </asp:DropDownList>
             </FooterTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="From Date" SortExpression="FromDate">
             <ItemTemplate><%# Eval("FromDate")%></ItemTemplate>
             <EditItemTemplate>
                 <asp:TextBox ID="txtFromDate" Text='<%# Eval("FromDate") %>' runat="server"></asp:TextBox>
                 <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
                 <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtFromDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton1">
                 </asp:CalendarExtender>
             </EditItemTemplate>
             <FooterTemplate>
                 <asp:TextBox ID="txtFromDate" Text='' runat="server"></asp:TextBox>
                 <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
                 <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtFromDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton1">
                 </asp:CalendarExtender>
             </FooterTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="To Date" SortExpression="ToDate">
             <ItemTemplate><%# Eval("ToDate")%></ItemTemplate>
             <EditItemTemplate>
                 <asp:TextBox ID="txtToDate" Text='<%# Eval("ToDate") %>' runat="server"></asp:TextBox>
                 <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
                 <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtToDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton2">
                 </asp:CalendarExtender>
             </EditItemTemplate>
             <FooterTemplate>
                 <asp:TextBox ID="txtToDate" Text='' runat="server"></asp:TextBox>
                 <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
                 <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtToDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton2">
                 </asp:CalendarExtender>
             </FooterTemplate>
         </asp:TemplateField>
         <asp:CommandField HeaderText="Edit" ShowEditButton="True" />
         <asp:TemplateField HeaderText="Delete">
             <ItemTemplate>
                 <asp:LinkButton ID="linkDeleteShow" CommandName="Delete" runat="server">Delete</asp:LinkButton>
             </ItemTemplate>
             <FooterTemplate>
                 <asp:LinkButton ID="linkAddShow" CommandName="AddShow" runat="server">Add</asp:LinkButton>
             </FooterTemplate>
         </asp:TemplateField>

         <asp:TemplateField>
             <ItemTemplate>
                 <tr>
                     <td colspan="100%">
                         <div id="div<%# Eval("ShowTimeId") %>" style="display:none;position:relative;left:15px;OVERFLOW: auto;WIDTH:97%" >

                         <asp:GridView ID="GridView2" AllowPaging="True" AllowSorting="true" BackColor="White" Width=100% Font-Size=X-Small
                             AutoGenerateColumns="false" Font-Names="Verdana" runat="server" ShowFooter="true"
                             OnPageIndexChanging="GridView2_PageIndexChanging" OnRowUpdating = "GridView2_RowUpdating" CssClass="Gridview"
                             OnRowCommand = "GridView2_RowCommand" OnRowEditing = "GridView2_RowEditing" GridLines=None
                             OnRowUpdated = "GridView2_RowUpdated" OnRowCancelingEdit = "GridView2_CancelingEdit" OnRowDataBound = "GridView2_RowDataBound"
                             OnRowDeleting = "GridView2_RowDeleting" OnRowDeleted = "GridView2_RowDeleted" OnSorting = "GridView2_Sorting"
                             BorderStyle=Double BorderColor="#0083C1">
                         <RowStyle BackColor="Gainsboro" />
                         <AlternatingRowStyle BackColor="White" />
                         <HeaderStyle BackColor="#0083C1" ForeColor="White"/>
                         <FooterStyle BackColor="White" />
                         <Columns>
                         <asp:TemplateField HeaderText="Show ID" SortExpression="ShowID">
                             <ItemTemplate>
                                 <asp:Label ID="lblShowID" Text='<%# Eval("ShowID") %>' runat="server"></asp:Label>
                             </ItemTemplate>
                             <EditItemTemplate>
                                 <asp:Label ID="lblShowID" Text='<%# Eval("ShowID") %>' runat="server"></asp:Label>
                             </EditItemTemplate>
                         </asp:TemplateField>
                         <asp:TemplateField HeaderText="ShowTime" SortExpression="ShowTime">
                             <ItemTemplate><%# Eval("ShowTime")%></ItemTemplate>
                             <EditItemTemplate>
                                 <asp:TextBox ID="txtShowTime" Text='<%# Eval("ShowTime")%>' runat="server"></asp:TextBox>
                             </EditItemTemplate>
                             <FooterTemplate>
                                 <asp:TextBox ID="txtShowTime" Text='' runat="server"></asp:TextBox>
                             </FooterTemplate>
                         </asp:TemplateField>
                         <asp:TemplateField HeaderText="Silver" SortExpression="Silver">
                             <ItemTemplate><%# Eval("Silver")%></ItemTemplate>
                             <EditItemTemplate>
                                 <asp:TextBox ID="txtSilver" Text='<%# Eval("Silver")%>' runat="server"></asp:TextBox>
                             </EditItemTemplate>
                             <FooterTemplate>
                                 <asp:TextBox ID="txtSilver" Text='' runat="server"></asp:TextBox>
                             </FooterTemplate>
                         </asp:TemplateField>
                         <asp:TemplateField HeaderText="Gold" SortExpression="Gold">
                             <ItemTemplate><%# Eval("Gold")%></ItemTemplate>
                             <EditItemTemplate>
                                 <asp:TextBox ID="txtGold" Text='<%# Eval("Gold")%>' runat="server"></asp:TextBox>
                             </EditItemTemplate>
                             <FooterTemplate>
                                 <asp:TextBox ID="txtGold" Text='' runat="server"></asp:TextBox>
                             </FooterTemplate>
                         </asp:TemplateField>
                         <asp:TemplateField HeaderText="Platinum" SortExpression="Platinum">
                             <ItemTemplate><%# Eval("Platinum")%></ItemTemplate>
                             <EditItemTemplate>
                                 <asp:TextBox ID="txtPlatinum" Text='<%# Eval("Platinum")%>' runat="server"></asp:TextBox>
                             </EditItemTemplate>
                             <FooterTemplate>
                                 <asp:TextBox ID="txtPlatinum" Text='' runat="server"></asp:TextBox>
                             </FooterTemplate>
                         </asp:TemplateField>
                         <asp:CommandField HeaderText="Edit" ShowEditButton="True" />
                         <asp:TemplateField HeaderText="Delete">
                              <ItemTemplate>
                                 <asp:LinkButton ID="linkDeleteCust" CommandName="Delete" runat="server">Delete</asp:LinkButton>
                              </ItemTemplate>
                              <FooterTemplate>
                                 <asp:LinkButton ID="linkAddOrder" CommandName="AddShow" runat="server">Add</asp:LinkButton>
                              </FooterTemplate>
                         </asp:TemplateField>
                         </Columns>
                         </asp:GridView>
                         </div>
                     </td>
                 </tr>
             </ItemTemplate>
         </asp:TemplateField>
     </Columns>
 </asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
     ConnectionString="<%$ ConnectionStrings:Event_MovieConnectionString %>"
     SelectCommand="SELECT s.[ShowTimeId], s.[TheatreId], s.[MovieId], s.[FromDate], s.[ToDate], s.[Created],
     s.[Modified], t.TheatreID, t.TheatreName, m.MovieID, m.MovieName FROM (([tbl_SShow] s inner join MST_Theatre t
     on s.TheatreId = t.TheatreID)inner join MST_Movie m on s.MovieId = m.MovieID) ORDER BY s.[ShowTimeId]">
 </asp:SqlDataSource>
   <asp:SqlDataSource ID="SqlDataSource2" runat="server"
     ConnectionString="<%$ ConnectionStrings:Event_MovieConnectionString %>"
     SelectCommand="SELECT TheatreID, TheatreName FROM MST_Theatre">
 </asp:SqlDataSource>


and CS file is :

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Drawing;
using BLL;


public partial class _Default : System.Web.UI.Page
{
clsbll b1 = new clsbll();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString.ToString());

string gvUniqueID = String.Empty;
int gvNewPageIndex = 0;
int gvEditIndex = -1;
string gvSortExpr = String.Empty;

private string gvSortDir
{

get { return ViewState["SortDirection"] as string ?? "ASC"; }

set { ViewState["SortDirection"] = value; }

}

//This procedure returns the Sort Direction
private string GetSortDirection()
{
switch (gvSortDir)
{
case "ASC":
gvSortDir = "DESC";
break;

case "DESC":
gvSortDir = "ASC";
break;
}
return gvSortDir;
}

//This procedure prepares the query to bind the child GridView

private SqlDataSource ChildDataSource(string strShowTimeId, string strSort)
{
string strQRY = "";
SqlDataSource dsTemp = new SqlDataSource();
dsTemp.ConnectionString = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString.ToString();
//dsTemp.DataFile = "App_Data/Northwind.mdb";
strQRY = "SELECT [tbl_Time].[ShowID],[tbl_Time].[ShowTime]," +
"[tbl_Time].[Silver],[tbl_Time].[Gold],[tbl_Time].[Platinum] FROM [tbl_Time]" +
" WHERE [tbl_Time].[ShowTimeId] = '" + strShowTimeId + "'" +
"UNION ALL " +
"SELECT '" + strShowTimeId + "','','','','' FROM [tbl_Time] WHERE [tbl_Time].[ShowTimeId] = '" + strShowTimeId + "'" +
"HAVING COUNT(*)=0 " + strSort;
dsTemp.SelectCommand = strQRY;

return dsTemp;
}

protected void Page_Load(object sender, EventArgs e)
{

}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
// start ddlMovie
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList cmbType = (DropDownList)e.Row.FindControl("ddlmovie");
if (cmbType != null)
{
SqlCommand cmd = new SqlCommand("select MovieName from MST_Movie ", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

cmbType.DataSource = dt;
cmbType.DataTextField = "MovieName";
cmbType.DataValueField = "MovieName";
cmbType.DataBind();
cmbType.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[0].ToString();
}
}
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList cmbNewType = (DropDownList)e.Row.FindControl("ddlMovie");
SqlCommand cmd = new SqlCommand("select MovieName from MST_Movie", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
cmbNewType.DataTextField = "MovieName";
cmbNewType.DataValueField = "MovieName";
cmbNewType.DataSource = dt;
cmbNewType.DataBind();
}
// end ddlMovie


GridViewRow row = e.Row;
string strSort = string.Empty;

// Make sure we aren't in header/footer rows
if (row.DataItem == null)
{
return;
}

//Find Child GridView control
GridView gv = new GridView();
gv = (GridView)row.FindControl("GridView2");

//Check if any additional conditions (Paging, Sorting, Editing, etc) to be applied on child GridView
if (gv.UniqueID == gvUniqueID)
{
gv.PageIndex = gvNewPageIndex;
gv.EditIndex = gvEditIndex;
//Check if Sorting used
if (gvSortExpr != string.Empty)
{
GetSortDirection();
strSort = " ORDER BY " + string.Format("{0} {1}", gvSortExpr, gvSortDir);
}
//Expand the Child grid
ClientScript.RegisterStartupScript(GetType(), "Expand", "<SCRIPT LANGUAGE='javascript'>expandcollapse('div" + ((DataRowView)e.Row.DataItem)["ShowTimeId"].ToString() + "','one');</script>");
}

//Prepare the query for Child GridView by passing the Customer ID of the parent row
gv.DataSource = ChildDataSource(((DataRowView)e.Row.DataItem)["ShowTimeId"].ToString(), strSort);
gv.DataBind();

//Add delete confirmation message for Customer
LinkButton l = (LinkButton)e.Row.FindControl("linkDeleteShow");
l.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this Show " +
DataBinder.Eval(e.Row.DataItem, "ShowTimeId") + "')");

}

//This event occurs for any operation on the row of the grid
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
//Check if Add button clicked
if (e.CommandName == "AddShow")
{
try
{
//Get the values stored in the text boxes
DropDownList strTheatreid = ((DropDownList)GridView1.FooterRow.FindControl("ddlTheatre"));
DropDownList strMovieid = ((DropDownList)GridView1.FooterRow.FindControl("ddlMovie"));
TextBox strFromDate = ((TextBox)GridView1.FooterRow.FindControl("txtFromDate"));
TextBox strToDate = ((TextBox)GridView1.FooterRow.FindControl("txtToDate"));

DateTime fromdate = DateTime.ParseExact(strFromDate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
DateTime Todate = DateTime.ParseExact(strToDate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

DateTime date = DateTime.Now;

//Prepare the Insert Command of the DataSource control
string strSQL = "";
strSQL = "INSERT INTO tbl_SShow VALUES ('" + Convert.ToInt32(strTheatreid.SelectedValue) + "','" + Convert.ToInt32(strMovieid.SelectedValue) + "','" + fromdate + "','" + Todate + "','" + date + "','" + date + "')";

SqlDataSource1.InsertCommand = strSQL;
SqlDataSource1.Insert();
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Theatre added successfully');</script>");

//Re bind the grid to refresh the data
GridView1.DataBind();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>");
}
}
}

//This event occurs on click of the Update button
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Get the values stored in the text boxes

string strTheatreid = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlTheatre")).SelectedValue;
string strMovieid = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlMovie")).SelectedValue;
string strFromDate = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtFromDate")).Text;
string strToDate = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtToDate")).Text;
string strShowTimwid = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblShowTimeId")).Text;


try
{
//Prepare the Update Command of the DataSource control
string strSQL = "";
strSQL = "UPDATE tbl_SShow set TheatreId = '" + Convert.ToInt32(strTheatreid) + "'" +
",MovieId = '" + strMovieid + "'" +
",FromDate = '" + strFromDate + "'" +
",ToDate = '" + strToDate + "'" +
" WHERE ShowTimeId = '" + Convert.ToInt32(strShowTimwid) + "'";
SqlDataSource1.UpdateCommand = strSQL;
SqlDataSource1.Update();
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Theatre updated successfully');</script>");
}
catch { }
}

//This event occurs after RowUpdating to catch any constraints while updating
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
//Check if there is any exception while deleting
if (e.Exception != null)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>");
e.ExceptionHandled = true;
}
}

//This event occurs on click of the Delete button
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//Get the value
string strShowTimeID = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblShowTimeId")).Text;

//Prepare the delete Command of the DataSource control
string strSQL = "";

try
{
strSQL = "DELETE from tbl_SShow WHERE ShowTimeId = '" + Convert.ToInt32(strShowTimeID) + "'";
SqlDataSource1.DeleteCommand = strSQL;
SqlDataSource1.Delete();
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Theatre deleted successfully');</script>");
}
catch { }
}

//This event occurs after RowDeleting to catch any constraints while deleting
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
//Check if there is any exception while deleting
if (e.Exception != null)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>");
e.ExceptionHandled = true;
}
}


protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvTemp = (GridView)sender;
gvUniqueID = gvTemp.UniqueID;
gvNewPageIndex = e.NewPageIndex;
GridView1.DataBind();
}

protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "AddShow")
{
try
{
GridView gvTemp = (GridView)sender;
gvUniqueID = gvTemp.UniqueID;

//Get the values stored in the text boxes
string strShowTimeId = gvTemp.DataKeys[0].Value.ToString(); //Customer ID is stored as DataKeyNames
string strShowTime = ((TextBox)gvTemp.FooterRow.FindControl("txtShowTime")).Text;
string strSilver = ((TextBox)gvTemp.FooterRow.FindControl("txtSilver")).Text;
string strGold = ((TextBox)gvTemp.FooterRow.FindControl("txtGold")).Text;
string strPlatinum = ((TextBox)gvTemp.FooterRow.FindControl("txtPlatinum")).Text;

//Prepare the Insert Command of the DataSource control
string strSQL = "";
strSQL = "INSERT INTO tbl_Time VALUES ('" + strShowTime + "','" + strSilver + "','" + strGold + "','" + strPlatinum + "','" + Convert.ToInt32(strShowTimeId) + "')";

SqlDataSource1.InsertCommand = strSQL;
SqlDataSource1.Insert();
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Time added successfully');</script>");

GridView1.DataBind();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>");
}
}
}

protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView gvTemp = (GridView)sender;
gvUniqueID = gvTemp.UniqueID;
gvEditIndex = e.NewEditIndex;
GridView1.DataBind();
}

protected void GridView2_CancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView gvTemp = (GridView)sender;
gvUniqueID = gvTemp.UniqueID;
gvEditIndex = -1;
GridView1.DataBind();
}

protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
GridView gvTemp = (GridView)sender;
gvUniqueID = gvTemp.UniqueID;

//Get the values stored in the text boxes
string strShowID = ((Label)gvTemp.Rows[e.RowIndex].FindControl("lblShowID")).Text;
string strShowTime = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtShowTime")).Text;
string strSilver = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtSilver")).Text;
string strGold = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtGold")).Text;
string strPlatinum = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtPlatinum")).Text;


//Prepare the Update Command of the DataSource control
SqlDataSource dsTemp = new SqlDataSource();
dsTemp.ConnectionString = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString.ToString();
string strSQL = "";
strSQL = "UPDATE tbl_Time set ShowTime = '" + strShowTime + "',Silver = '" + strSilver + "' ,Gold = '" + strGold + "',Platinum = '" + strPlatinum + "' WHERE ShowID = '" + strShowID+"' ";
dsTemp.UpdateCommand = strSQL;
dsTemp.Update();
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Order updated successfully');</script>");

//Reset Edit Index
gvEditIndex = -1;

GridView1.DataBind();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>");
}
}

protected void GridView2_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
//Check if there is any exception while deleting
if (e.Exception != null)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>");
e.ExceptionHandled = true;
}
}

protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridView gvTemp = (GridView)sender;
gvUniqueID = gvTemp.UniqueID;

//Get the value
string strShowID = ((Label)gvTemp.Rows[e.RowIndex].FindControl("lblShowID")).Text;

//Prepare the Update Command of the DataSource control
string strSQL = "";

try
{
strSQL = "DELETE from tbl_Time WHERE ShowID = " + strShowID;
SqlDataSource dsTemp = new SqlDataSource();
dsTemp.ConnectionString = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString.ToString();
dsTemp.DeleteCommand = strSQL;
dsTemp.Delete();
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Show deleted successfully');</script>");
GridView1.DataBind();
}
catch { }
}

protected void GridView2_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
//Check if there is any exception while deleting
if (e.Exception != null)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>");
e.ExceptionHandled = true;
}
}

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Check if this is our Blank Row being databound, if so make the row invisible
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (((DataRowView)e.Row.DataItem)["ShowID"].ToString() == String.Empty) e.Row.Visible = false;
}
}

protected void GridView2_Sorting(object sender, GridViewSortEventArgs e)
{
GridView gvTemp = (GridView)sender;
gvUniqueID = gvTemp.UniqueID;
gvSortExpr = e.SortExpression;
GridView1.DataBind();
}
}

modified 29-Aug-13 4:07am.

GeneralRe: gridview inside gridview with update delete Pin
Dholakiya Ankit2-Sep-13 0:35
Dholakiya Ankit2-Sep-13 0:35 
GeneralRe: gridview inside gridview with update delete Pin
vipulparmar902-Sep-13 18:49
vipulparmar902-Sep-13 18:49 
GeneralRe: gridview inside gridview with update delete Pin
vipulparmar901-Sep-13 19:20
vipulparmar901-Sep-13 19:20 
QuestionNeed advice - Designing ASP application Pin
Boipelo3-Aug-13 5:14
Boipelo3-Aug-13 5:14 
AnswerRe: Need advice - Designing ASP application Pin
Boipelo5-Aug-13 4:11
Boipelo5-Aug-13 4:11 
GeneralRe: Need advice - Designing ASP application Pin
AnalogNerd5-Aug-13 5:33
AnalogNerd5-Aug-13 5:33 
GeneralRe: Need advice - Designing ASP application Pin
Boipelo5-Aug-13 6:03
Boipelo5-Aug-13 6:03 
QuestionAsp.net application css issue Pin
kulldeep verma3-Aug-13 4:26
kulldeep verma3-Aug-13 4:26 
AnswerRe: Asp.net application css issue Pin
jkirkerx3-Aug-13 12:40
professionaljkirkerx3-Aug-13 12:40 
AnswerRe: Asp.net application css issue Pin
Dholakiya Ankit7-Aug-13 20:02
Dholakiya Ankit7-Aug-13 20:02 
Questiononline model Pin
durgesh j2-Aug-13 20:34
durgesh j2-Aug-13 20:34 
AnswerRe: online model Pin
Richard MacCutchan2-Aug-13 22:00
mveRichard MacCutchan2-Aug-13 22:00 
AnswerRe: online model Pin
Ajay 101865622-Aug-13 23:03
professionalAjay 101865622-Aug-13 23:03 
QuestionMathematical, Physics and Chemistry Symbols tools for ASP.NET Pin
Olamiji Akeem Odeyemi2-Aug-13 2:29
Olamiji Akeem Odeyemi2-Aug-13 2:29 
Questionneed help Pin
snehal1222-Aug-13 1:54
snehal1222-Aug-13 1:54 
AnswerRe: need help Pin
Richard MacCutchan2-Aug-13 3:08
mveRichard MacCutchan2-Aug-13 3:08 
QuestionAsp.net, javascript : Textbox issue with chrome and firefox. pls help me out Pin
christhuxavier2-Aug-13 1:12
christhuxavier2-Aug-13 1:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.