-1

我是初学者。单选按钮无法正常工作。我不知道有什么问题

protected void RadioButton1_CheckedChanged1(object sender, EventArgs e)
{
    if (RadioButton1.Checked == true)
    {
        Label1.Text = "Upload our video file";
        RadioButton2.Checked = false;
    }
    else
    {
        Label1.Text = "Upload our image file";
        RadioButton1.Checked = false;
    }
}
public void upload()
{
    SqlCommand cmd = new SqlCommand("insert into video_info(Name,path,user_name,email,comment)values(@Name,@path,@user_name,@email,@comment)", con);
    cmd.Parameters.AddWithValue("@Name", txt_file.Text);
    cmd.Parameters.AddWithValue("@path", "video/" + fileuplod.FileName);
    cmd.Parameters.AddWithValue("@user_name", use_name.Text);
    cmd.Parameters.AddWithValue("@email", email.Text);
    cmd.Parameters.AddWithValue("@comment", comment.Text);
    fileuplod.SaveAs(Server.MapPath("~/video/" + fileuplod.FileName));
    cmd.ExecuteNonQuery();
}
protected void submit_Click(object sender, EventArgs e)
{
    upload();
}

}

我想要做什么。我有两个单选按钮。图像和视频。假设用户选择图像。然后所有细节都将保存在图像表上,或者如果用户单击视频。所有细节都转到 image_database。

可能是我的逻辑错了。

4

2 回答 2

2

在单选按钮属性中将自动回发设置为 true

于 2013-04-04T10:23:55.780 回答
1
Try this 
public void upload(string query)
{
    SqlCommand cmd = new SqlCommand(query, con);
    cmd.Parameters.AddWithValue("@Name", txt_file.Text);
    cmd.Parameters.AddWithValue("@path", "video/" + fileuplod.FileName);
    cmd.Parameters.AddWithValue("@user_name", use_name.Text);
    cmd.Parameters.AddWithValue("@email", email.Text);
    cmd.Parameters.AddWithValue("@comment", comment.Text);
    fileuplod.SaveAs(Server.MapPath("~/video/" + fileuplod.FileName));
    cmd.ExecuteNonQuery();
}
protected void submit_Click(object sender, EventArgs e)
{
 string query;
if (RadioButton1.Checked == true)
    {

       query="insert into video_info(Name,path,user_name,email,comment)values(@Name,@path,@user_name,@email,@comment)";
       Label1.Text = "Upload our video file";
        RadioButton2.Checked = false;
    }
    else
    {

       query="insert into Image_info(Name,path,user_name,email,comment)values(@Name,@path,@user_name,@email,@comment)";
       Label1.Text = "Upload our image file";
        RadioButton1.Checked = false;
    }
  if(query!="")
    {
       upload(query);
    }

}
于 2013-04-04T10:28:23.290 回答