鉴于大家对ASP.net十分关注,我们编辑小组在此为大家搜集整理了“gridview 中RadioButton 的使用”一文,供大家参考学习
本来是想模仿C/S的样子完成单击一列直接触发事件,后来知道那样要用到AJAX,最后还是用了RadioButton这样实现起来相对简单,不过只能在要求不高是时候用。
使用这个先要在gridview 里放入RadioButton模板。然后激发它的checked事件然后在此事件里可以捕捉到点的那一列,要注意就是点完了要将RadioButton的checked设置为false,这样看不到刚点过的痕迹,不过也算凑合能是些头的任务.....
protected void OrdersGridView_ClickChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in this.OrdersGridView.Rows)
{
RadioButton radioButton = (RadioButton)row.FindControl("RadioButton1");
if (radioButton.Checked)
{
//显示从表内容
int i = Convert.ToInt32(radioButton.Text);
string sqlstr = "SELECT * FROM [Order Details] where orderID=’" + i + "’ ORDER BY [OrderID]";
string TableName = "OrderDetails";
GridViewBind(sqlstr, TableName, OrderDetailsGridView);
radioButton.Checked = false;
}
}
/// <summary>
/// 根据tablename和sql语句绑定GridView1到数据库
/// </summary>
/// <param name="sqlstr"></param>
/// <param name="tablename"></param>
/// <param name="GridView1"></param>
protected void GridViewBind(string sqlstr, string tablename,GridView GridView1)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
本新闻共3页,当前在第1页 1 2 3