gpt4 book ai didi

asp.net - 在asp.net中获取radgrid telerik隐藏列的值

转载 作者:行者123 更新时间:2023-12-04 16:26:11 25 4
gpt4 key购买 nike

我有一个 radgrid,我在其中隐藏了 Id 列。现在我想在链接按钮点击时获得它的值(value)。如果列可见,它工作正常,但

它在不可见时显示空白值。我的代码是

 protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == "Detail")
{
GridDataItem dataItm = e.Item as GridDataItem;

string value = dataItm["Id"].Text;
}
}

最佳答案

请尝试使用以下代码片段。

ASPX

 <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
OnItemCommand="RadGrid1_ItemCommand">
<MasterTableView DataKeyNames="ID">
<Columns>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID1" HeaderText="ID" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID2" HeaderText="ID" Display="false">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CommandName="Detail" CommandArgument='<%# Eval("ID") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>

ASPX文件
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="Name1"},
new { ID = 2, Name = "Name2"},
new { ID = 3, Name = "Name3"},
new { ID = 4, Name = "Name4"},
new { ID = 5, Name = "Name5"}
};

RadGrid1.DataSource = data;

}

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "Detail")
{
GridDataItem item = e.Item as GridDataItem;

string strID = item.GetDataKeyValue("ID").ToString(); // We are able to get ID field value here
string strID1 = item["ID1"].Text; // We are NOT able to get ID field value here Because column is Visible false
string strID2 = item["ID2"].Text; // We are able to get ID field value here
string strCommandArgument = e.CommandArgument.ToString(); // We are able to get ID field value here

}
}

请使用 显示器 属性(property)代替 可见 属性(property)。

关于asp.net - 在asp.net中获取radgrid telerik隐藏列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17230423/

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