http://topic.youkuaiyun.com/u/20070128/00/cd19d943-5835-422c-a839-fa2f555f5e8d.html
让我头痛的GridView Template DropdownList ObjectDataSource...强汗无法传参数
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Update ")
{
string StudentTitle = ((TextBox)GridView1.Rows[GridView1.EditIndex].FindControl( "uTitle ")).Text;
string StudentBirthDay = ((TextBox)
GridView1.Rows[GridView1.EditIndex].FindControl( "uBirthDay ")).Text;
bool StudentGender = ((RadioButtonList)
GridView1.Rows[GridView1.EditIndex].FindControl( "uGender ")).SelectedValue == "男 " ? true : false;
string StudentClassName = ((DropDownList)
GridView1.Rows[GridView1.EditIndex].FindControl( "uClassName ")).SelectedValue;
string StudentID = GridView1.DataKeys[GridView1.EditIndex].Value.ToString();
String FileName = " ";
string sql = " ";
String PhotoPath = " ";
sql = "Update Student Set Title=@Title,BirthDay = @BirthDay, " ;
sql += "Gender=@Gender,ClassName=@ClassName Where id=@id ";
SqlDataSource1.UpdateCommand = sql;
SqlDataSource1.UpdateCommandType = SqlDataSourceCommandType.Text;
SqlDataSource1.UpdateParameters.Add( "@Title ", TypeCode.String, StudentTitle);
SqlDataSource1.UpdateParameters.Add( "@BirthDay ", TypeCode.DateTime, StudentBirthDay);
SqlDataSource1.UpdateParameters.Add( "@Gender ", TypeCode.Boolean, StudentGender.ToString());
if (HasFileUploaded)
{
SqlDataSource1.UpdateParameters.Add( "@PhotoPath ", TypeCode.String, PhotoPath);
}
SqlDataSource1.UpdateParameters.Add( "@ClassName ", TypeCode.String, StudentClassName);
SqlDataSource1.UpdateParameters.Add( "@id ", TypeCode.Int32, StudentID);
SqlDataSource1.Update();
}
}
GridViewObjectDataSource
最新推荐文章于 2020-03-03 12:50:40 发布