在按钮上单击网格视图中的选择行 [英] On button click select row in gridview

查看:68
本文介绍了在按钮上单击网格视图中的选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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>



但不起作用,请帮助我.
谢谢...



but not working it please help me.
thanks...

推荐答案

在行命令事件中的代码后面的代码尝试通过以下方式进行操作

in the row command event in code behind try that in the following way

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];
  }


这篇关于在按钮上单击网格视图中的选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆