在asp.net vs05上工作。我有一个网格
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
DataKeyNames="StudentID" OnSelectedIndexChanged="GridView3_SelectedIndexChanged"
OnRowDataBound="GridView3_RowDataBound">
<Columns>
<asp:BoundField DataField="StudentID" HeaderText="StudentID" ReadOnly="True"
SortExpression="StudentID" />
<asp:BoundField DataField="StudentName" HeaderText="StudentName" />
<asp:TemplateField HeaderText="DivisionName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("StudentName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
Width="160px"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Button" CommandName="Select" HeaderText="Update"
Text="Update" />
</Columns>
</asp:GridView>
使用按钮单击我想在数据库上保存值。但我无法从下拉列表中读取值
protected void GridView3_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow selectRow = GridView3.SelectedRow;
String ID = selectRow.Cells[0].Text;
String Name = selectRow.Cells[1].Text;
//String Dis = selectRow.Cells[2].Text;
String Dis =
((DropDownList)sender).FindControl("DropDownList1").ToString();
//**want to get this value**
}
我如何获得ddl选择值?我想将类的对象放在ddl .Bellow代码在桌面上工作,在网络上同样的事情。
DropDownList1.DisplayMember = "CommercialRegionName";
foreach (class oItem in _collection)
{
DropDownList1.Items.Add(oItem);
//**want to save object,Not any object item like:oItem.Name.**
}
答案 0 :(得分:0)
protected void GridView3_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow selectRow = GridView3.SelectedRow;
String ID = selectRow.Cells[0].Text;
String Name = selectRow.Cells[1].Text;
//String Dis = selectRow.Cells[2].Text;
//PROBABLY YOU WANT TO GET ITEM FROM SELECTED ROW'S DROPDOWN
var ddl = (selectRow).FindControl("DropDownList1") as DropdownList;
if(dis!=null){
var s=ddl.SelectedItem.Text;
}
}