我試圖從ButtonField(數據綁定)訪問文本,但如果我將它作爲TableCell引用,則無法獲取文本。我能做些什麼來獲得它的文本?如何訪問ButtonFields文本,如果它不被視爲TableCell?
標記:
<asp:GridView ID="gvClass" runat="server" CssClass="grid" HeaderStyle-Font-Bold="true" Width="100%" OnSelectedIndexChanged="gvClass_SelectedIndexChanged" DataKeyNames="ClassID" AutoGenerateColumns="False" OnPageIndexChanging="gvClass_PageIndexChanging">
<HeaderStyle Font-Bold="True" />
<Columns>
<asp:ButtonField DataTextField="ClassID" HeaderText="Class ID" CommandName="Select" />
<asp:BoundField DataField="CourseName" HeaderText="Course Name" />
<asp:BoundField DataField="WarehouseName" DataFormatString="Warehouse" HeaderText="Warehouse" />
<asp:BoundField DataField="TrainerNames" HeaderText="Trainer(s)" />
<asp:BoundField DataField="StartTime" HeaderText="Start Time" />
<asp:BoundField DataField="Duration" HeaderText="Duration" />
<asp:BoundField DataField="Course Category" HeaderText="Course Category" />
<asp:BoundField DataField="Comment" HeaderText="Comment" />
</Columns>
<EmptyDataTemplate>
<span class="italic grey">No Record Found</span>
</EmptyDataTemplate>
</asp:GridView>
代碼隱藏:
foreach (GridViewRow gvr in gvClass.Rows)
{
foreach (TableCell tc in gvr.Cells)
{
stringToAppend = tc.Text;
sb.Append(PRTL_UtilityPackage.FormatHtmlCharacters(stringToAppend) + " \t");
}
sb.Append("\\n");
}
在foreach(TableCell的TC在gvr.Cells)看ButtonField字段時爲空字符串出現。
適合我的最佳方法 – wubblyjuggly 2015-12-30 16:50:06