2

これは私のマークアップです:-

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        Width="245px" onrowcommand="GridView1_RowCommand" >
        <Columns>

            <asp:TemplateField>
            <ItemStyle BackColor="#CCCCCC" ForeColor="Black" Width="250px" HorizontalAlign="Center"
                    BorderStyle="None" />
                    <ItemTemplate>
                        <asp:LinkButton ID="userList" runat="server" CommandName="Select" CommandArgument ='<%# Container.DataItemIndex %>' Text='<%# Bind("users") %>'></asp:LinkButton>
                    </ItemTemplate>
            </asp:TemplateField>

        </Columns>        
    </asp:GridView>

コードビハインドでは、現在の行のテキスト値を取得しようとしていますが、取得できないようです。

"" を返します。

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int rowValue = Convert.ToInt32(e.CommandArgument.ToString());
    GridView1.SelectedIndex = rowValue;
    string test = GridView1.SelectedRow.Cells[0].Text;
}
4

2 に答える 2

7

コントロールを見つけてアクセスする必要があります

LinkButton btn = (LinkButton)gvDealerSupportMail.Rows[rowValue].FindControl("userList");
string result = btn.Text;
于 2015-05-05T06:52:08.780 に答える
1

、および CommandSourceを取得するために使用できます。Command.TextCommandNameCommandArgument

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        LinkButton commandSource = e.CommandSource as LinkButton;
        string commandText = commandSource.Text;
        string commandName = commandSource.CommandName;
        int commandArgument = Convert.ToInt32(commandSource.CommandArgument);
    }
于 2015-05-05T07:18:26.697 に答える