【问题标题】:How to access boundfield values in a Gridview Control?如何访问 Gridview 控件中的 boundfield 值?
【发布时间】:2011-07-12 15:35:00
【问题描述】:

我有一个网格视图控件,其中包含一些绑定和模板字段,如下所示

<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
ReadOnly="True" SortExpression="ID" Visible="False" />
<asp:TemplateField HeaderText="Question">
<ItemTemplate>
<asp:LinkButton ID="btnques" runat="server" onclick="btnques_Click" 
Text='<%# bind("Question") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

现在,我想做的是在按钮btnques 的单击事件上,我想访问其对应的边界字段ID 的值并将其存储在标签中。谁能告诉我怎么做...

【问题讨论】:

    标签: c# asp.net gridview controls boundfield


    【解决方案1】:

    应该像

     Text='<%# bind("Question") %> CommandArgument='<%# Eval("QuestionId") %>'
    

    然后在后面的代码中你就可以访问...

    protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "")
        {
           e.CommandArgument // will return the id 
        }        
    }
    

    【讨论】:

      猜你喜欢
      • 2013-09-10
      • 2013-11-20
      • 2010-10-11
      • 2013-05-09
      • 2011-03-06
      • 2011-05-14
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      相关资源
      最近更新 更多