7楼的写法本身就有问题,首先我们要判断e.RowIndex是否合法,其次我们不能保证我们FindControl的结果!=null,这样直接.SelectedValue就会变成一个引用异常。正确的写法应该大致如下: 以下代码来源MSDN: void CustomersGridView_RowUpdating(Object sender, GridViewUpdateEventArgs e) { // Iterate through the NewValues collection and HTML encode all // user-provided values before updating the data source. foreach (DictionaryEntry entry in e.NewValues) { e.NewValues[entry.Key] = Server.HtmlEncode(entry.Value.ToString()); } } // Find control on page. Control myControl1 = FindControl("TextBox2"); if(myControl1!=null)
不知楼主问题卡在哪里?
<asp:TemplateField HeaderText="质量更改从">
<ItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
>
</asp:DropDownList>
</ItemTemplate>
在一个griedview里面,运行后id被改了。
里可以
string name = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList4")).SelectedValue;
但是 protected void OnSelectedIndexChanged(Object sender,EventArgs e)
这里没有e.rowindex
以下代码来源MSDN: void CustomersGridView_RowUpdating(Object sender, GridViewUpdateEventArgs e)
{ // Iterate through the NewValues collection and HTML encode all
// user-provided values before updating the data source.
foreach (DictionaryEntry entry in e.NewValues)
{ e.NewValues[entry.Key] = Server.HtmlEncode(entry.Value.ToString()); } }
// Find control on page.
Control myControl1 = FindControl("TextBox2");
if(myControl1!=null)
{
string name = ((DropDownList)this.GridView1.SelectedRow.Cells[0].FindControl("DropDownList4")).SelectedValue;
}
是抄你自己7楼的写法的,还以为你要在那里写嘛,呵呵,我也纳闷你怎么会在那里写。HOHO,找对了就好。