Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Iam selecting a particular row(or a 3rd row) from gridview using dropdownlist,then when I click edit the editmode is pointing to a firstrow of a grid instead the row which I have selected to edit.plzz help.Thanks.
Posted
Comments
Hitesh Varde 12-May-14 8:04am    
Can you please provide some code you implemented for gridview to get better idea for your query?
saisrid 12-May-14 8:30am    
this is my gridview in aspx page:

<asp:GridView ID="GridView1" runat="server" CellPadding="4" DataKeyNames="Nric" OnRowCancelingEdit="canceledit"
ForeColor="#333333" OnRowUpdating="UpdateCustomer" AutoGenerateColumns="False"
OnRowEditing="editEmployee" OnRowCommand="GridView1_RowCommand">


<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />



<asp:CommandField ShowEditButton="true" />
<asp:TemplateField HeaderText="ID" Visible="false">

<asp:Label ID="Label4" runat="server" Text='<%# Bind("ID") %>'>


<asp:TemplateField HeaderText="File Name">

<asp:Label ID="Label1" runat="server" Text='<%# Bind("FilesName") %>'>


<asp:TemplateField HeaderText="Nric">

<asp:Label ID="Label2" runat="server" Text='<%# Bind("Nric") %>'>


<asp:TemplateField HeaderText="Description">

<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Description") %>'>


<asp:Label ID="Label3" runat="server" Text='<%# Bind("Description") %>'>


<asp:TemplateField ItemStyle-HorizontalAlign="Center">

<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="DownloadFile"
CommandArgument='<%# Eval("ID") %>'>



<asp:TemplateField>

<asp:LinkButton ID="lnkRemove" runat="server" CommandArgument='<%# Eval("ID")%>'
OnClientClick="return confirm('Do you want to delete?')" Text="Delete" ForeColor="Red"
OnClick="DeleteEmployee">





this is my codebehind:
protected void editEmployee(object sender,GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindGrid();

}
how to give the rowindex, also I have tried but I cannot fix it.

1 solution

most probably in the editbutton click method you may be using wrong code like the one below.
You must use the code as following .
gv.EditIndex=e.RowIndex;

after the above code you must rebind grid view controls data using datasource and databind propert and methods .
 
Share this answer
 
Comments
saisrid 12-May-14 8:16am    
Thanks for your response.
this is my gridview in aspx page:

<asp:GridView ID="GridView1" runat="server" CellPadding="4" DataKeyNames="Nric" OnRowCancelingEdit="canceledit"
ForeColor="#333333" OnRowUpdating="UpdateCustomer" AutoGenerateColumns="False"
OnRowEditing="editEmployee" OnRowCommand="GridView1_RowCommand">
<rowstyle backcolor="#EFF3FB">
<footerstyle backcolor="#507CD1" font-bold="True" forecolor="White">
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<editrowstyle backcolor="#2461BF">
<alternatingrowstyle backcolor="White">
<columns>
<asp:CommandField ShowEditButton="true" />
<asp:TemplateField HeaderText="ID" Visible="false">
<itemtemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("ID") %>'>


<asp:TemplateField HeaderText="File Name">
<itemtemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FilesName") %>'>


<asp:TemplateField HeaderText="Nric">
<itemtemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Nric") %>'>


<asp:TemplateField HeaderText="Description">
<edititemtemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Description") %>'>

<itemtemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Description") %>'>


<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="DownloadFile"
CommandArgument='<%# Eval("ID") %>'>

<itemstyle horizontalalign="Center">

<asp:TemplateField>
<itemtemplate>
<asp:LinkButton ID="lnkRemove" runat="server" CommandArgument='<%# Eval("ID")%>'
OnClientClick="return confirm('Do you want to delete?')" Text="Delete" ForeColor="Red"
OnClick="DeleteEmployee">





this is my codebehind:
protected void editEmployee(object sender,GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindGrid();

}
how to give the rowindex, also I have tried but I cannot fix it.

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