Last post Oct 17, 2017 03:05 AM by Cathy Zou
Member
389 Points
965 Posts
Oct 16, 2017 10:45 AM|cms9651|LINK
Hi there,
I have problem using RowEditing on GridView in c#
With this ImageButton I selected in GridView only rows where my email address is registered :
<asp:ImageButton ID="btnOnly" ImageUrl="/images/show_icon.gif" Visible="true" runat="server" OnClick="btnOnly_Click" CommandArgument="1" CommandName="1" /> protected void btnOnly_Click(object sender, ImageClickEventArgs e) { btn = (ImageButton)sender; CommandName = btn.CommandName; CommandArgument = btn.CommandArgument; BindData(); } SELECT * FROM doTable WHERE doEmail IN ('myemail') ORDER BY ID DESC;
In this new view of GridView when I selected row for Edit :
<asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server" ImageUrl="/Images/edit.gif" />
In GridView is opened for edit the row of first view.
The first row where there are other email addresses other than my email address:
protected void gvProducts_RowEditing(object sender, GridViewEditEventArgs e) { gvProducts.EditIndex = e.NewEditIndex; BindData(); }
Can you help me?
Thank you in advance for any help, really appreciated.
Star
8670 Points
2882 Posts
Oct 17, 2017 03:05 AM|Cathy Zou|LINK
Hi cms9651,
Form your description and code, it is hard for me to understand your problem.
Would you please provided more detailed description about you problem with complete code?
Following is a working sample I used to test, it works well.
You could take a look:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="Id" OnRowEditing="GridView1_RowEditing"> <Columns> <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" /> <asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="100" /> <asp:TemplateField> <ItemTemplate> <asp:ImageButton ID="btnOnly" ImageUrl="~/images/thumb-1.gif" Visible="true" runat="server" CommandArgument="1" CommandName="Edit" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
CodeBehind:
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { BindData(); } } protected void BindData() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Id"), new DataColumn("Group"), new DataColumn("Name"), new DataColumn("Country") }); dt.Rows.Add(1, "A", "John Hammond", "United States"); dt.Rows.Add(2, "B", "Mudassar Khan", "India"); dt.Rows.Add(3, "A", "Suzanne Mathews", "France"); dt.Rows.Add(4, "B", "Robert Schidner", "Russia"); GridView1.DataSource = dt; GridView1.DataBind(); } protected void btnOnly_Click(object sender, ImageClickEventArgs e) { ImageButton btn = (ImageButton)sender; string CommandName = btn.CommandName; string CommandArgument = btn.CommandArgument; } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; BindData(); }
Best Regards
Cathy
Member
389 Points
965 Posts
RowEditing in GridView in c#
Oct 16, 2017 10:45 AM|cms9651|LINK
Hi there,
I have problem using RowEditing on GridView in c#
With this ImageButton I selected in GridView only rows where my email address is registered :
In this new view of GridView when I selected row for Edit :
In GridView is opened for edit the row of first view.
The first row where there are other email addresses other than my email address:
Can you help me?
Thank you in advance for any help, really appreciated.
Cheers,
Chevy Mark Sunderland
Star
8670 Points
2882 Posts
Re: RowEditing in GridView in c#
Oct 17, 2017 03:05 AM|Cathy Zou|LINK
Hi cms9651,
Form your description and code, it is hard for me to understand your problem.
Would you please provided more detailed description about you problem with complete code?
Following is a working sample I used to test, it works well.
You could take a look:
CodeBehind:
Best Regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.