Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 15-Feb-15 19:57pm
v3
Comments
Monicavensaslas 16-Feb-15 2:37am    
using telerik gridview you can directly update the details in the row itself.
Refer this link for telerik grid view..

http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx
Encap 17-Feb-15 0:58am    
In My Task I Should Not Use SQL Database.All Editings In Grid View Should Bind To The DataTable

1 solution

 
Share this answer
 
Comments
Encap 17-Feb-15 0:58am    
In My Task I Should Not Use SQL Database.All Editings In Grid View Should Bind To The DataTable
[no name] 17-Feb-15 1:05am    
chk this http://stackoverflow.com/questions/573518/bind-a-datatable-to-a-gridview-and-add-edit-capability-to-the-grid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900