Dear All I want to get select a row when i click on button in gridview this is my code:<pre> <asp:GridView ID="grdvwIndiMemSlab" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" Width="457px" OnRowDataBound="grdvwIndiMemSlab_RowDataBound" OnRowCommand="grdvwIndiMemSlab_RowCommand" GridLines="None"> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#FFFBD6" ForeColor="#333333" /> <Columns> <asp:TemplateField> <HeaderStyle BorderWidth="1" VerticalAlign="top" /> <ItemStyle Width="50px" BorderWidth="1" VerticalAlign="Top" /> <ItemTemplate> <asp:LinkButton runat="server" CommandName='<%#Eval("ExpectedDate") %>' ID="btnSelect" CommandArgument='<%#Eval("MemberID") %>' Text="Select"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> <asp:TemplateField Visible="false" HeaderText="Member ID"> <HeaderStyle BorderWidth="1" VerticalAlign="top" /> <ItemStyle BorderWidth="1" VerticalAlign="Top" /> <ItemTemplate> <center> <asp:Label ID="lblMId" runat="server" Width="50" Text='<%#Eval("MemberID") %>'></asp:Label></center> </ItemTemplate> </asp:TemplateField> <asp:TemplateField Visible="false" HeaderText="Member Name"> <HeaderStyle BorderWidth="1" VerticalAlign="top" /> <ItemStyle BorderWidth="1" VerticalAlign="Top" /> <HeaderStyle VerticalAlign="top" /> <ItemTemplate> <center> <asp:Label ID="lblname" runat="server" Width="120" Text='<%#Eval("MemberName") %>'></asp:Label></center> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Expected Date"> <HeaderStyle BorderWidth="1" VerticalAlign="top" /> <ItemStyle Width="110px" BorderWidth="1" VerticalAlign="Top" /> <HeaderStyle VerticalAlign="top" /> <ItemTemplate> <center> <asp:Label ID="lblExpectedDate" runat="server" Width="120" Text='<%# string.Format("{0:dd/MMM/yyyy}", Eval("ExpectedDate")) %>'></asp:Label></center> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Work Name"> <HeaderStyle BorderWidth="1" VerticalAlign="top" /> <ItemStyle Width="110px" BorderWidth="1" VerticalAlign="Top" /> <HeaderStyle VerticalAlign="top" /> <ItemTemplate> <center> <asp:Label ID="lblWork" runat="server" Width="110" Text='<%#Eval("WorkName") %>'></asp:Label></center> </ItemTemplate> </asp:TemplateField> <%-- <asp:TemplateField HeaderText="Consume Slab"> <HeaderStyle BorderWidth="1" VerticalAlign="top" /> <ItemStyle BorderWidth="1" HorizontalAlign="Center" VerticalAlign="Top" /> <ItemTemplate> <asp:DropDownList ID="drpDwnLstCnsmdSlb" runat="server" CssClass="input_text"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField>--%> </Columns> <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView>
if(e.CommandName=="Add")// your Command Name "exact ExpectedDate in your case " { // Convert the row index stored in the CommandArgument //property to an Integer. int index = Convert.ToInt32(e.CommandArgument); // Retrieve the row that contains the button clicked // by the user from the Rows collection. GridViewRow row = CustomersGridView.Rows[index]; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)