[英]How to display some text in a GridView button
I have the following code which is a GridView: 我有以下代码是GridView:
<asp:GridView ID="BookingResults" runat="server" EnableModelValidation="True" OnRowCommand="BookingResults_RowCommand" AutoGenerateColumns="False">
<Columns>
<asp:ButtonField Text=" " ButtonType="Button" CommandName="ViewAll" HeaderText="Show Guideline" ItemStyle-HorizontalAlign="Center">
</asp:ButtonField>
<asp:BoundField DataField="ID" HeaderText="ID" ItemStyle-VerticalAlign="Top" />
<asp:BoundField DataField="Topic" HeaderText="Topic" SortExpression="Topic" ItemStyle-VerticalAlign="Top" />
<asp:BoundField DataField="Location" HeaderText="Location" ItemStyle-VerticalAlign="Top" />
<asp:BoundField DataField="Specialty" HeaderText="Specialty" ItemStyle-VerticalAlign="Top" />
<asp:BoundField DataField="Provider" HeaderText="Provider" ItemStyle-VerticalAlign="Top" />
<asp:TemplateField HeaderText="Summary" ItemStyle-VerticalAlign="Top">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Summary") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Summary") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Guideline" HeaderText="Guideline" />
</Columns>
</asp:GridView>
The end result is this: 最终结果是这样的:
I can't seem to give the ButtonField
an ID so I can display text per line. 我似乎不能给
ButtonField
一个ID,所以我可以每行显示文本。 How can I display an increment value from 1 and so forth in the button from code-behind? 如何在代码后面的按钮中显示从1开始的增量值,依此类推?
Tap into RowDataBound event, and add the logic: 点击进入RowDataBound事件,然后添加逻辑:
var btn = (IButtonControl)e.Row.Cells[0].Controls[0];
btn.Text = indexVariable;
The button is usually the first control of the cell you defined it, which since it's the first column, would be cell index zero. 该按钮通常是您定义它的单元格的第一个控件,由于它是第一列,因此它将是单元格索引零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.