日期:2014-05-18  浏览次数:20852 次

如何获取gridView 中的dropDownList 名称??
如何获取gridView 中的dorpDownList 名称??
dropDownList 是gridView中的一模版列!!

------解决方案--------------------
C# code

((DropDownList)(gridView1.Rows[e.RowIndex].Cells[inedx].FindControl("DropDownList1"))).SelectedValue.ToString().Trim()

------解决方案--------------------
HTML code

<asp:TemplateField HeaderText="DropDownList " HeaderStyle-BackColor="#8bb9ee">
                        <ItemTemplate>
                        <asp:DropDownList ID="DropDownList1" Width="120px" runat="server"></asp:DropDownList>
                        </ItemTemplate>
                </asp:TemplateField>

------解决方案--------------------
string y = int.Parse(((DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlDepart")).ClientID);
------解决方案--------------------
HTML code

<asp:TemplateField HeaderText="学历">
  <ItemTemplate>
     <%# Eval("xueliText")%>
       </ItemTemplate>
           <EditItemTemplate>
             <asp:DropDownList ID="DDLXueli" runat="server" Width="90px" />
           </EditItemTemplate>
  <ItemStyle Width="100px" />
</asp:TemplateField>

------解决方案--------------------
string xueli = (GridView1.Rows[e.RowIndex].FindControl("DDLXueli") as DropDownList).SelectedValue;

------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 

if (e.Row.RowType == DataControlRowType.DataRow) 

System.Data.DataRowView drv = (System.Data.DataRowView)e.Row.DataItem; RadioButtonList rbl = (RadioButtonList)e.Row.FindControl("txtGender"); 
if (rbl != null) 

if ((bool)drv["Gender"]) 

rbl.Items.FindByText("男").Selected = true; 

else 

rbl.Items.FindByText("女").Selected = true; 



DropDownList ddl = (DropDownList)e.Row.FindControl("txtClassName"); 
if (ddl != null) 

ddl.Items.FindByValue(drv["ClassID"].ToString()).Selected = true; ///这是根据VALUE查找 




------解决方案--------------------
探讨
dorpDownList 名称是指什么?

------解决方案--------------------
名称当然是说他的ID
string y = int.Parse(((DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlDepart")).ClientID);
------解决方案--------------------

1.当知道每一个DropDownList的Name的时候。
string xueli = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1")).SelectedValue;或者(SelectedItem.Text)
2.当不知道DropDownList的Name的时候。
 string xueli = ((DropDownList)GridView1.Rows[e.RowIndex].Controls[0]).SelectedValue;或者(SelectedItem.Text)
------解决方案--------------------
探讨
C# code((DropDownList)(gridView1.Rows[e.RowIndex].Cells[inedx].FindControl("DropDownList1"))).SelectedValue.ToString().Trim()