求助:未赋值的局部变量
问题:使用了未赋值的局部变量“dg”“flag”,代码如下:protected void Button1_Click(object sender, EventArgs e)
{
int flag;
DataGrid dg;
if (rad1.Checked)
{
flag = 0;
dg = DataGrid1;
}
else if (rad2.Checked)
{
flag = 1;
dg = DataGrid2;
}
else
{
Response.Write("<script defer>alert('请选择必/选修项');</script>");
}
foreach (DataGridItem Item in dg.Items)
{
if (Item.ItemType == ListItemType.Item || Item.ItemType == ListItemType.AlternatingItem)
{
RadioButton radID = ((RadioButton)Item.FindControl("rad"));
if (radID.Checked == true)
{
int num = int.Parse(Item.Cells[0].Text);
string name=Item.Cells[1].Text;
int period = int.Parse(Item.Cells[2].Text);
string Cmd3 = "insert into lab_stu_course(user_ID,Cou_num,Cou_name,Cou_flag,Cou_period) values('" + Session["user_ID"].ToString() + "','" + num + "','" + name + "','"+ flag +"','" + period + "')";
Comm1 add_course = new Comm1();
add_course.ENQ(Cmd3);
}
大家帮忙看看怎么改?