2011-09-07 88 views
1
读一个下拉列表

我有一个gridview,一个field作为dropdownlist .. 我想读的dropdownlist但在列表中的第一项总是selectedvalues ..从GridView控件

此代码是在GridView里面:

<asp:TemplateField HeaderText="Bank"> 
    <ItemTemplate> 
     <asp:DropDownList ID="DropDown" runat="server" OnLoad="dropdownLoad" /> 
      </ItemTemplate> 
     </asp:TemplateField> 

在后端,我使用下面的代码:

​​

我该怎么办?

+1

你的意思是,即使更改选择后,显示的第一个项目? – V4Vendetta

+0

@ V4Vendetta是的...我从列表中选择一个不同的项目,当我点击一个按钮来读取输入的值,它将始终显示列表的第一个值,而不是选定的值... – cgval

+1

你能添加代码段上你是如何分配数据 – V4Vendetta

回答

0

不要搜索特定的单元格。相反,我会建议你在自己的行中搜索下拉列表。

因此,代码应该有的东西一样:

DropDownList ddl = GridView1.Rows[0].FindControl("DropDown") as DropDownList; 

欢呼。

2

试试这个代码..

 GridViewRow row = (GridViewRow)((Control)sender).NamingContainer; 
     DropDownList drp = (DropDownList)row.FindControl("drp"); 
     lbl.Text = drp.SelectedValue;