sri divya

sri divya

  • NA
  • 2
  • 2k

Editmode is pointing to a different record in gridview

May 13 2014 1:58 AM
Hi,
 
Using a dropdownlist iam selecting a row in gv(8th record),so now the gv is displaying only one row(8th record),when I click edit ,the editmode is pointing to first record in the grid(so now the grid is showing all the records and the editmode is pointing to the firstrecord in the gv).
 
I wanted the editmode to be pointing to the record which I have selected.
I have tried the rowindex in many ways,but I couldn't fix it .Plz help.
 
Thanks.
 

this is mycodebehind:
 
protected void editEmployee(object sender,GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;//here I should give the control
BindGrid();
 
}
 
 
this is my gv 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:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="File Name">

<ItemTemplate>

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

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Nric">

<ItemTemplate>

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

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Description">

<EditItemTemplate>

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

</EditItemTemplate>

<ItemTemplate>

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

</ItemTemplate>

</asp:TemplateField>

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

<ItemTemplate>

<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="DownloadFile"

CommandArgument='<%# Eval("ID") %>'></asp:LinkButton>

</ItemTemplate>

<ItemStyle HorizontalAlign="Center"></ItemStyle>

</asp:TemplateField>

<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"></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

<%--<asp:CommandField ShowDeleteButton="true" />--%>

</Columns>

</asp:GridView>


Answers (2)