如何在 Telerik RadGrid 中选择行?

发布于 2024-12-19 22:35:03 字数 123 浏览 2 评论 0原文

当用户在 Telerik Rad Grid 中选择一行时,我想获取该行中的字段。怎么办?

When user select a row in Telerik Rad Grid, i want to take fields in this row. how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夢归不見 2024-12-26 22:35:03

这有点棘手,但完成一次后就很容易了。

第 1 步。

转到 Radgrid 本身并编辑字段 DataKeyNames=""(在 MasterTableView 下),然后添加您要提取的数据字段:

<MasterTableView ... DataKeyNames="ColumnNameFromSqlGoesHere">

第 2 步。

决定如何进行要获取值,请在“行更改”(SelectedIndexChanged) 上或按下带有附加命令的按钮 (ItemCommand)。

如果行发生变化,根据您的问题:

protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
    var z = RadGrid1.SelectedItems[0].OwnerTableView.DataKeyValues[RadGrid1.SelectedItems[0].ItemIndex]["ColumnNameFromSqlGoesHere"];
}

这会将变量“z”分配给您在该给定行中选择的列的值 (ColumnNameFromSqlGoesHere)。

如果您希望每次更改行时选择多个变量,则需要在 DataKeyNames=" " 下添加您希望选择的所有值。 (以逗号分隔)。然后,您将通过 SelectedIndexChanged 方法中看到的代码获取每个值:

var a = RadGrid1.SelectedItems[0].OwnerTableView.DataKeyValues[RadGrid1.SelectedItems[0].ItemIndex]["SecondColumnGoesHere"];

var b = RadGrid1.SelectedItems[0].OwnerTableView.DataKeyValues[RadGrid1.SelectedItems[0].ItemIndex]["ThirdColumnGoesHere"];

等等...您明白了。

It's a little tricky, but easy after you've done it once.

Step 1.

Go to the Radgrid itself and edit the field DataKeyNames="" (under MasterTableView) and add the datafield you are pulling:

<MasterTableView ... DataKeyNames="ColumnNameFromSqlGoesHere">

Step 2.

Decide how you are going to grab the values, on Row Change (SelectedIndexChanged) or on a buttong press with a command attached to it (ItemCommand).

If row change, per your question:

protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
    var z = RadGrid1.SelectedItems[0].OwnerTableView.DataKeyValues[RadGrid1.SelectedItems[0].ItemIndex]["ColumnNameFromSqlGoesHere"];
}

This will assign the variable "z" to the value of the column you have chosen (ColumnNameFromSqlGoesHere) at that given row.

If you wish to select multiple variables every time you change row you need to add all the values you wish to select under the DataKeyNames=" ". (Seperated by commas). You would then fetch each value via the code seen in the SelectedIndexChanged method:

var a = RadGrid1.SelectedItems[0].OwnerTableView.DataKeyValues[RadGrid1.SelectedItems[0].ItemIndex]["SecondColumnGoesHere"];

var b = RadGrid1.SelectedItems[0].OwnerTableView.DataKeyValues[RadGrid1.SelectedItems[0].ItemIndex]["ThirdColumnGoesHere"];

Etc... You get the idea.

情未る 2024-12-26 22:35:03

这应该能让你继续前进。这是直接来自 Telerik 的解决方案:检索所选项目的主键值

This should get you going. It is a solution straight from Telerik: Retrieving primary key values for selected items

讽刺将军 2024-12-26 22:35:03

试试这个。这可能对你有帮助。

第 1 步:在 radgrid 中添加一个单选按钮列

第 1 步:获取 radgrid 中所选行的主键。

    int primaryKey =0;
    RadioButton radioButton;  
    for (int i = 0; i < RadGrid1.Items.Count; i++)  
    {  
        radioButton = RadGrid1.Items[i].FindControl("rdSelect") as RadioButton;
        If (radioButton.Checked)
        { 
           primaryKey = RadGrid1.MasterTableView.Items[e.Item.ItemIndex]["ID"].Text;
        }
    }

if 中的行 条件将用于通过更改字段数据键名称来获取所选行中的字段,即将“ID”更改为其他字段

阅读本文了解更多详细信息...

http://codedotnets.blogspot.in/2012/01/get -primary-key-selected-radiobutton.html

Try this. This may help you.

STEP 1:Add one radiobutton column in the radgrid

STEP 1: Get the primary key of selected row in the radgrid.

    int primaryKey =0;
    RadioButton radioButton;  
    for (int i = 0; i < RadGrid1.Items.Count; i++)  
    {  
        radioButton = RadGrid1.Items[i].FindControl("rdSelect") as RadioButton;
        If (radioButton.Checked)
        { 
           primaryKey = RadGrid1.MasterTableView.Items[e.Item.ItemIndex]["ID"].Text;
        }
    }

Line in the if condition will be used to get the fields from the selected row just by changing the fields datakey name i.e. changing "ID" to other field

Read this article for more details...

http://codedotnets.blogspot.in/2012/01/get-primary-key-selected-radiobutton.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文