界面安放了3个单选按钮 保存时分别是若选 radiobutton1 数据库存A radiobutton2 数据库存B radiobutton3 数据库存C 3个radiobutton在一个groupbox里 当我要修改此界面数据 调出时 我如何用BINDING来绑定这三个控件 binding = new Binding("checked", dsMain.Tables[0], "service_request", true);
binding.Format += new ConvertEventHandler(binding_Format);
前面不知道加什么了 DataBindings.Add(binding);
下面的感觉也不对劲
void binding_Format(object sender, ConvertEventArgs e)
{
string val = dsMain.Tables[0].Rows[0]["service_request"].ToString(); switch (val) { case "A": { e.Value = "A"; this.radioButton1.Checked = true; this.radioButton2.Checked = false; this.radioButton3.Checked = false; break; } case "B": { e.Value = "B"; this.radioButton1.Checked = false; this.radioButton2.Checked = true; this.radioButton3.Checked = false; break; } case "C": { e.Value = "C"; this.radioButton1.Checked = false; this.radioButton2.Checked = false; this.radioButton3.Checked = true; break; }
}
//throw new Exception("The method or operation is not implemented.");
}
binding.Format += new ConvertEventHandler(binding_Format);
前面不知道加什么了 DataBindings.Add(binding);
下面的感觉也不对劲
void binding_Format(object sender, ConvertEventArgs e)
{
string val = dsMain.Tables[0].Rows[0]["service_request"].ToString(); switch (val) { case "A": { e.Value = "A"; this.radioButton1.Checked = true; this.radioButton2.Checked = false; this.radioButton3.Checked = false; break; } case "B": { e.Value = "B"; this.radioButton1.Checked = false; this.radioButton2.Checked = true; this.radioButton3.Checked = false; break; } case "C": { e.Value = "C"; this.radioButton1.Checked = false; this.radioButton2.Checked = false; this.radioButton3.Checked = true; break; }
}
//throw new Exception("The method or operation is not implemented.");
}
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatColumns="3" >
<asp:ListItem Value ="0" Selected ="True ">A</asp:ListItem>
<asp:ListItem Value ="1">B</asp:ListItem>
<asp:ListItem Value ="2" Text ="haha">C</asp:ListItem>
</asp:RadioButtonList>通过RadioButtonList1.SelectedValue值来设置那个被选中即可。
...
RadioButtonList1.Items.FindByValue(val).Selected = true;