如何在GridView模板的下拉列表中设置谷 [英] how to set the vale in Drop down in gridview template Colums
本文介绍了如何在GridView模板的下拉列表中设置谷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将Gridview与Dropdown的Templete字段一起使用
在RowdtatBound,我使用一个返回数据表的函数,并将其与
绑定
DropDown的模板列.
之后,当我尝试在Dropdown的Templete Field中选择值时
它给了我
的错误
对象引用未设置为对象的实例."
尽管我尝试在下拉列表中设置的数据首先是因为我
填充下拉菜单,然后使用
设置值
I am Using Gridview with templete Field of DropDown
at RowdtatBound I Use a function which returns datatable and I bind it with
template column of DropDown.
After that when i try to select the value in templete Field of DropDown
It gives me error of
"Object reference not set to an instance of an object."
although the data which i try to set in dropdown its present becuase first i
populate the dropdown and then set the value by using
gvReading_ddlgv.Items.FindByValue(strLastReading).Selected = True
出现问题需要帮助!!!
Whts the problem Need Help !!!
推荐答案
,
手动在源文件和.cs文件中写入dropdown selectindexchanged事件,并设置autopostback = true.然后在selectedindexchanged事件中使用sender对象获取组合框selectedindex和文本,并使用dropdownlist clientid获取所选行,如
simply,
manually write dropdown selectindexchanged event in sourcefile and .cs file and set autopostback=true.then in selectedindexchanged event use sender object to retreive combobox selectedindex and text and use dropdownlist clientid to get selected row like
DropDownList ddl = (DropDownList)sender;
string s = ddl.ClientID;//use substring to retreive rowindex
if (ddl.SelectedItem.Text == "Your selected text"){dropdown1.Items.FindByText("Your text"].ToString()).Selected=true;}
这篇关于如何在GridView模板的下拉列表中设置谷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文