gridview中radiobutton实现单选的问题,我的代码中老是说 row.ItemIndex缺少using引用怎么办,急等
//RadioButton的CheckedChanged事件protectedvoidrb_CheckedChanged(objectsender,EventArgse)...
//RadioButton的CheckedChanged事件
protected void rb_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb != null)
{
GridViewRow row = rb.Parent as GridViewRow;
//row.FindControl( " ")获取该行中其他控件的值
//...
//把行index保存在ViewState中
ViewState[ "rowIndex "] = row.ItemIndex;
}
BindData(); //重新绑定GridView
}
//GridView的OnRowDataBound事件
protected void Bound(object sender, GridViewRowEventArgs e)
{
if (ViewState[ "rowIndex "] != null)
{
int index = int.Parse(ViewState[ "rowIndex "].ToString());
if (e.Row.RowIndex == index)
{
RadioButton rb = e.Row.FindControl( "rb ") as RadioButton;
if (rb != null)
rb.Checked = true;
}
}
} 展开
protected void rb_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb != null)
{
GridViewRow row = rb.Parent as GridViewRow;
//row.FindControl( " ")获取该行中其他控件的值
//...
//把行index保存在ViewState中
ViewState[ "rowIndex "] = row.ItemIndex;
}
BindData(); //重新绑定GridView
}
//GridView的OnRowDataBound事件
protected void Bound(object sender, GridViewRowEventArgs e)
{
if (ViewState[ "rowIndex "] != null)
{
int index = int.Parse(ViewState[ "rowIndex "].ToString());
if (e.Row.RowIndex == index)
{
RadioButton rb = e.Row.FindControl( "rb ") as RadioButton;
if (rb != null)
rb.Checked = true;
}
}
} 展开
展开全部
ViewState[ "rowIndex "] = row.ItemIndex;
改下试试
gridview1.row.ltemindex;
int rowindex = ((GridViewRow)(((CheckBox)sender).NamingContainer)).RowIndex; //此语句可以取行号
CheckBox cb;
cb = (CheckBox)GridView1.Rows[rowindex].FindControl("cb_state"); //GRIDVIEW 中建立模板模板中放了一个交"cb_state"的CHECKBOX
string id = GridView1.DataKeys[rowindex].Value.ToString();//获取当前行的主键(当然绑定GV的时候你得绑定主键啦)
后面的代码就根据的的希望进行操作就行了,毕竟主键都出来了。
这个是我昨天晚上写的一个在GRIDVIEW中应用CHECKBOX的 方法,改成RB控件就可以了。。。希望对你有参考价值
改下试试
gridview1.row.ltemindex;
int rowindex = ((GridViewRow)(((CheckBox)sender).NamingContainer)).RowIndex; //此语句可以取行号
CheckBox cb;
cb = (CheckBox)GridView1.Rows[rowindex].FindControl("cb_state"); //GRIDVIEW 中建立模板模板中放了一个交"cb_state"的CHECKBOX
string id = GridView1.DataKeys[rowindex].Value.ToString();//获取当前行的主键(当然绑定GV的时候你得绑定主键啦)
后面的代码就根据的的希望进行操作就行了,毕竟主键都出来了。
这个是我昨天晚上写的一个在GRIDVIEW中应用CHECKBOX的 方法,改成RB控件就可以了。。。希望对你有参考价值
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询