在页面notesort的地方动态添加RadioButton后,想根据选择不同的RadioButton来显示不同的内容。
代码如下:
-----------------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
string sql="select id,sortName from T_noteSort where parentid=0";
Run_P.GetDs(sql,"T_noteSort");
int cc=1;
//---------------在notesort处动态添加RadioButton foreach ( DataRow ii in Run_P.ds.Tables["T_noteSort"].Rows ){
RadioButton myRB = new RadioButton();
myRB.ID = "RB"+cc;
myRB.GroupName= "ntSortname";
myRB.Text = ii["sortName"].Tostring();
myRB.CheckedChanged +=new EventHandler(myRB_CheckedChanged);
this.notesort.Controls.Add(myRB);
cc++;
}
}
}
//---------------------------------------------------------------触发的事件
private void myRB_CheckedChanged(object sender, EventArgs e)
{
string sql="select id,sortname from T_noteSort where id="+e.Tostring();
Run_P.GetDs(sql,"T_noteSort");
this.sortname.text=Run_P.ds.Tables["T_noteSort"].Rows[0]["sortname"].Tostring();}
//---------------------------------------------------------------在页面中notesort位置添加动态RadioButton成功,但是事件不能触发,是为什么?
不知道写在触发事件中获取动态生成的RadioButton提交过来的value的方法是不是对的?
请高手指点。还有个问题就是,动态生成的RadioButton在页面中查看源代码看到的是:
<input id="RB1" type="radio" name="ntSortname" value="RB1" /><label for="RB1">科技话题</label>
我怎么才能让id和value不一致了?好像RadioButton控件不能设置value的值一样,要如何设置RadioButton的value值了?
代码如下:
-----------------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
string sql="select id,sortName from T_noteSort where parentid=0";
Run_P.GetDs(sql,"T_noteSort");
int cc=1;
//---------------在notesort处动态添加RadioButton foreach ( DataRow ii in Run_P.ds.Tables["T_noteSort"].Rows ){
RadioButton myRB = new RadioButton();
myRB.ID = "RB"+cc;
myRB.GroupName= "ntSortname";
myRB.Text = ii["sortName"].Tostring();
myRB.CheckedChanged +=new EventHandler(myRB_CheckedChanged);
this.notesort.Controls.Add(myRB);
cc++;
}
}
}
//---------------------------------------------------------------触发的事件
private void myRB_CheckedChanged(object sender, EventArgs e)
{
string sql="select id,sortname from T_noteSort where id="+e.Tostring();
Run_P.GetDs(sql,"T_noteSort");
this.sortname.text=Run_P.ds.Tables["T_noteSort"].Rows[0]["sortname"].Tostring();}
//---------------------------------------------------------------在页面中notesort位置添加动态RadioButton成功,但是事件不能触发,是为什么?
不知道写在触发事件中获取动态生成的RadioButton提交过来的value的方法是不是对的?
请高手指点。还有个问题就是,动态生成的RadioButton在页面中查看源代码看到的是:
<input id="RB1" type="radio" name="ntSortname" value="RB1" /><label for="RB1">科技话题</label>
我怎么才能让id和value不一致了?好像RadioButton控件不能设置value的值一样,要如何设置RadioButton的value值了?
动态创建的控件每次页面加载时都要创建,而不仅仅是第一次
还有如何指定<input id="RB1" type="radio" name="ntSortname" value="RB1" /><label for="RB1">科技话题</label>
中的value值了?他老是和id同步
那个VALUE..我也不懂.
该用js能解决部分问题,不过得自己写不少javascript了