开发者

How to access boundfield values in a Gridview Control?

开发者 https://www.devze.com 2023-02-15 19:41 出处:网络
I have a grid view control having some bound and template fields as follows <asp:BoundField DataField=\"ID\" HeaderText=\"ID\" InsertVisible=\"False\"

I have a grid view control having some bound and template fields as follows

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

Now, what I want to do is that on the click event of a buttom btnques, I want to access its corressponding boundfield ID's value and store it in a label. Can anyone tell me how to do this ...


should be like

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

and then in code behind you can acess like...

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号