网友回复:自己总结:几天了自己搞定。controlid只能是页面上的controlid,这点可能有点片面但是在线MSDN上写的就是页面上的而没说所有的控件。那就只能退而求其次。
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
ControlParameter cp_roleid =
new ControlParameter( "role_id ", TypeCode.String, GridView1.Rows[GridView1.EditIndex].FindControl( "DropDownList1 ").UniqueID.ToString(), "SelectedValue ");
SqlDataSource1.UpdateParameters.Add(cp_roleid);}
这个role_id就是SQL里的参数。而GridView1.Rows[GridView1.EditIndex].FindControl( "DropDownList1 ").本来是直接点tostring后来发现不行。又忽然发现这个uniqueid。一试居然通过,回想刚开始时假如有这个uniqueid不就直接可以写入controlid,行不行不知道,估计不行。因为dropdownlist是在编辑状态下才生成的,这个uniqueid应该也是在编辑时才生成的。这个方法应该也是最快的方法了,其实自己取得值。再保存是可以,只是我嫌速度慢。OK。好想结贴。可它总是没法结贴。到底是我的问题还是的问题。同时感谢上面各位大大们的意见,谢了。
网友回复:在编辑时取所选行的索引,然后根据rows.cell[index].constrol[第几个单元格]就OK了
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
ControlParameter cp_roleid =
new ControlParameter( "role_id ", TypeCode.String, GridView1.Rows[GridView1.EditIndex].FindControl( "DropDownList1 ").UniqueID.ToString(), "SelectedValue ");
SqlDataSource1.UpdateParameters.Add(cp_roleid);}
这个role_id就是SQL里的参数。而GridView1.Rows[GridView1.EditIndex].FindControl( "DropDownList1 ").本来是直接点tostring后来发现不行。又忽然发现这个uniqueid。一试居然通过,回想刚开始时假如有这个uniqueid不就直接可以写入controlid,行不行不知道,估计不行。因为dropdownlist是在编辑状态下才生成的,这个uniqueid应该也是在编辑时才生成的。这个方法应该也是最快的方法了,其实自己取得值。再保存是可以,只是我嫌速度慢。OK。好想结贴。可它总是没法结贴。到底是我的问题还是的问题。同时感谢上面各位大大们的意见,谢了。
网友回复:在编辑时取所选行的索引,然后根据rows.cell[index].constrol[第几个单元格]就OK了