gpt4 book ai didi

c# - 如果 ButtonFields 文本不被视为 TableCell,我如何访问它?

转载 作者:太空宇宙 更新时间:2023-11-03 17:58:54 25 4
gpt4 key购买 nike

我正在尝试从 ButtonField(数据绑定(bind))访问文本,但如果我将它作为 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(gvr.Cells 中的 TableCell tc)在查看 ButtonField 时出现一个空字符串。

最佳答案

您仍然可以使用 tablecell 方法:

protected void myGridView_DataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// You may have to play with the index of the control
// I have found that often a GridView will place a
// Literal control as Control[0] and the LinkButton
// as Control[1]. Once you find the index, it won't
// change.
LinkButton btn = (LinkButton)e.Row.Cells[0].Controls[1];
string text = btn.Text;
}
}

关于c# - 如果 ButtonFields 文本不被视为 TableCell,我如何访问它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4760465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com