We have a GridView2 in GridView1 EditTemplate.
And we have a button (commandname="U pdate") on GridView2.
When Button1 is clicked GridView1 goes into edit mode and displays GridView2.
Now when Button2 is Clicked, we want the cell[0] value of GridView2 to be displayed as Label1 Text on GridView1 and come out of the GridView1 edit mode.
Basically we want to capture gridView2 cell[0] value and display that on Label1 of GridView1.
We have written the below code. But we are unsure on how to grab GridView2.cell[0] value and display it as Label1 text.
Can someone please assist us with this?
Also, we are not sure if we can use rowupdated event for this. Please also guide us which events we should be using to achieve the functionality. Sample code would help us..
Thanks and much appreciated..
//GridView1 is binded in this method
//Child gridView binding in GridView1 Row Editing
And we have a button (commandname="U pdate") on GridView2.
When Button1 is clicked GridView1 goes into edit mode and displays GridView2.
Now when Button2 is Clicked, we want the cell[0] value of GridView2 to be displayed as Label1 Text on GridView1 and come out of the GridView1 edit mode.
Basically we want to capture gridView2 cell[0] value and display that on Label1 of GridView1.
We have written the below code. But we are unsure on how to grab GridView2.cell[0] value and display it as Label1 text.
Can someone please assist us with this?
Also, we are not sure if we can use rowupdated event for this. Please also guide us which events we should be using to achieve the functionality. Sample code would help us..
Thanks and much appreciated..
Code:
<asp:GridView ID="GridView1" runat="server" OnRowEditing="GridView1_RowEditing" Width="434px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="label1" runat="server" />
<asp:Button ID="Button1" CommandName="Edit" runat="server" Text="Button" />
</ItemTemplate>
<EditItemTemplate>
<asp:GridView ID="GridView2" runat="server" OnRowUpdated="GridView2_RowUpdated">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button2" CommandName="Update" runat="server" Text="Select" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
//GridView1 is binded in this method
Code:
public void ActivityDataBind()
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
Code:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
GridView1.EditIndex =e.NewEditIndex;
ActivityDataBind();
GridView gv=(GridView)(GridView1.Rows[e.NewEditIndex].Cells[0].FindControl("GridView2"));
DataTable dt=new DataTable();
// All the databinding table stuff code goes here.....
gv.DataSource = dt;
gv.DataBind();
}
catch(Exception ei)
{
Response.Write(ei.Message.ToString());
}
}
Comment