在GridView索引中选择了DropDownList [英] DropDownList in GridView index selected
问题描述
晕,当从其他页面打开页面时,我需要帮助设置DropDownList中的选定索引,问题是我不知道如何使用GridView中的DropDownList来执行此操作.有人可以告诉我如何执行此操作吗?
Hallo, I need help in setting the selected index in the DropDownList when the page is opened from a different page, the problem is I don''t know how to do this with the DropDownList in the GridView. Can anyone show me how to do this please?
推荐答案
请参阅以下链接
http://www.aspnettutorials.com/tutorials/controls/dropdownlist-gridview-csharp.aspx [ ^ ]
http://programming.top54u.com/post/Gridview-DropDownList-SelectedValue- in-ASP-Net.aspx [ ^ ]
http://www.codeproject.com/KB/webforms/DropdownInsideGridview.aspx [ ^ ]
Refer the below links
http://www.aspnettutorials.com/tutorials/controls/dropdownlist-gridview-csharp.aspx[^]
http://programming.top54u.com/post/Gridview-DropDownList-SelectedValue-in-ASP-Net.aspx[^]
http://www.codeproject.com/KB/webforms/DropdownInsideGridview.aspx[^]
您好...
在其中存在GridView和DropDownList的页面....
...我想您的GridView ID是 gdvUser ,而DropDownList id是 drpUser ......将这些行设置为索引...,而您只绑定了一条记录到GridView ...
Hi there...
At the page where your GridView and DropDownList in it exists....
... I suppose your GridView Id is gdvUser and DropDownList id is drpUser... put these line to set index... and you''re binding only one record to the GridView...
DropDownList drpL = (DropDownList) gdvUser.Rows[0].FindControl("drpUser");
drpL.SelectedIndex = 0; // I set 0 you can set it to any existing index
在上面的代码中,我假设您只填充一条记录,所以我将Row定为GridView中的位置0.您可以根据需要定位任何行.如果要为GridView中的所有记录设置DropDownList索引,则可以使用for循环...
In above code, I supposed you''re filling only one record so I targeted Row at position 0 in GridView. You can target any row as per your requirement. In case you want to set DropDownList index for all records in GridView, you can use for loop...
for(int i=0;i<gdvUser.Rows.Count;i++)
{
DropDownList drpL = (DropDownList) gdvUser.Rows[i].FindControl("drpUser");
drpL.SelectedIndex = 0; // I set 0 you can set it to any existing index
}
您还可以使用item的Text或Value属性找到下拉列表中的Item.
例子:
Also you can find an Item of dropdown list using Text or Value properties of item.
Examples:
DropDownList drpL = (DropDownList) gdvUser.Rows[0].FindControl("drpUser");
drpL.clearSelection();
drpL.Items.FindByText("SomeText").Selected = true;
DropDownList drpL = (DropDownList) gdvUser.Rows[0].FindControl("drpUser");
drpL.clearSelection();
drpL.Items.FindByValue("SomeValue").Selected = true;
DropDownList drpL = (DropDownList) gdvUser.Rows[0].FindControl("drpUser");
ListItem li = new ListItem("SomeText","SomeValue");
drpL.clearSelection();
drpL.Items[li].Selected = true;
注意:在上述三个示例中,在以编程方式选择新项目之前清除选择很重要,否则一次显示的错误最多只能选择一个ListItem.
希望您得到查询的解决方案.祝你好运! :)
Note: In above three examples it''s important to clear the selection before programmatically selecting a new item, otherwise an error will be shown about no more than a ListItem can be selected at a time.
I hope you got the solution of your query. Good Luck! :)
这篇关于在GridView索引中选择了DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!