In My Web Application There are two grid view's one is for adding columns another is for editing and updating
webform.aspx
<asp:GridView ID ="GVDETAILS" runat="server" AutoGenerateColumns="false"
onrowcommand="GVDETAILS_RowCommand" OnRowEditing="GVUPDATE_RowEditing"
onrowupdating="GVDETAILS_RowUpdating"
onselectedindexchanged="GVDETAILS_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:TextBox ID="TxtName" runat="server">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GENDER">
<ItemTemplate>
<asp:DropDownList ID="DDLGender" runat="server">
<asp:ListItem Value="0" Text="MALE">
</asp:ListItem>
<asp:ListItem Value="1" Text="FEMALE"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RESULT">
<ItemTemplate>
<asp:RadioButton ID="RB" Text="PASS" runat="server" />
<asp:RadioButton ID ="RB1" Text="FAIL" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Button" Text="ADD" CommandName="ADD" />
</Columns>
</asp:GridView>
<asp:GridView ID="GVUPDATE" runat="server" onrowediting="GVUPDATE_RowEditing"></asp:GridView>
<asp:Button ID="btnedit" runat="server" Text="EDITALL" />
<asp:Button ID="btnupdate" runat="server" Text="UPADTEALL" Width="103px" />
</div>
</form>
</body>
</html>
weform.cs file:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable _dt = new DataTable();
_dt.TableName = "Details";
_dt.Columns.Add("Name", typeof(string));
_dt.Columns.Add("Gender", typeof(string));
_dt.Columns.Add("Result", typeof(string));
DataRow _dr;
_dr = _dt.NewRow();
_dt.Rows.Add(_dr);
ViewState["Details"] = _dt;
GVDETAILS.DataSource = _dt;
GVDETAILS.DataBind();
}
}
protected void GVUPDATE_RowEditing(object sender, GridViewEditEventArgs e)
{
GVUPDATE.EditIndex = e.NewEditIndex;
GVUPDATE.DataBind();
}
protected void GVDETAILS_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ADD")
{
if (ViewState["Details"] != null)
{
DataTable dt = (DataTable)ViewState["Details"];
DataRow dr = dt.NewRow();
int index = Convert.ToInt32(e.CommandArgument.ToString());
GridViewRow gvr = GVDETAILS.Rows[index];
dr[0] = ((TextBox)gvr.FindControl("TxtName")).Text;
dr[1] = ((DropDownList)gvr.FindControl("DDLGender")).SelectedValue;
if (((RadioButton)gvr.FindControl("RB")).Checked == true)
{
dr[2] = "pass";
}
else
{
dr[2] = "fail";
}
dt.Rows.Add(dr);
GVUPDATE.DataSource = dt;
GVUPDATE.DataBind();
}
}
}
PROBLEM:Only one row is editing...all other rows can't been edited
plzz help me... thanks in advance