千家信息网

ASP.NET中RadioButtonList绑定后台数据后触发点击事件怎么用

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,这篇文章主要介绍ASP.NET中RadioButtonList绑定后台数据后触发点击事件怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!首先前台页面放置一个RadioBut
千家信息网最后更新 2026年10月31日ASP.NET中RadioButtonList绑定后台数据后触发点击事件怎么用

这篇文章主要介绍ASP.NET中RadioButtonList绑定后台数据后触发点击事件怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

首先前台页面放置一个RadioButtonList 控件

    

.cs文件 后台绑定数据

namespace BTApp{ public partial class Technology : System.Web.UI.Page {  string Id;  protected void Page_Load(object sender, EventArgs e)  {   if (!IsPostBack)   {    AspNetPager1.PageSize = 10;    if (Request.QueryString["Id"] != null)    {     Id = Request.QueryString["Id"];    }    else    { Id = ""; }    GetDataBind(Id);    DropDownListDataBind();   }  }  //RadioButtonList绑定后台数据  private void DropDownListDataBind()  {   ExpertInfoBLL bll = new ExpertInfoBLL();   DataTable dt = bll.GetDepInfo();   foreach (DataRow dr in dt.Rows)   {    RadioButtonList1.Items.Add(dr["Name"].ToString());//循环读出数据库的数据       }   this.RadioButtonList1.DataSource = dt;   this.RadioButtonList1.DataTextField = "Name";   this.RadioButtonList1.DataValueField = "Id";   this.RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal;   this.RadioButtonList1.DataBind();    }  private void GetDataBind(string Id)  {   //这里写解码和数据库返回结果   TechnologyBLL bll = new TechnologyBLL();   string strWhere = " 1=1 ";   if (Id != "" && Id != null)   {    strWhere += string.Format(" and a.Depinfo_Id = '{0}'", Id);   }   AspNetPager1.RecordCount = bll.GetCountList(strWhere);   //绑定数据    DataTable dt = bll.GetList((AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize, AspNetPager1.PageSize, strWhere, "CreateTime");   this.Repeater1.DataSource = dt;   this.Repeater1.DataBind();  }  protected void AspNetPager1_PageChanged(object sender, EventArgs e)  {   GetDataBind(Id);  }//根据选择单选按钮的不同id,触发事件  protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)  {    string Id;    Id = RadioButtonList1.SelectedValue;    GetDataBind(Id);  }   }}

TechnologyBLL 层的方法

namespace BTAppBLL{ public class TechnologyBLL {  TechnologyDAL dal = new TechnologyDAL();  public DataTable GetList(int startPage, int pageSize, string where, string orderby)  {   DataTable dTable = dal.GetList(startPage, pageSize, where, orderby);   return dTable;  }  public int GetCountList(string where)  {   int record = dal.GetCountList(where);   return record;  }  public DataTable GetListShow(string TechnologyId)  {   DataTable dTable = dal.GetModel(TechnologyId);   return dTable;  }  public DataTable GetPicture(string TechnologyId)  {   DataTable dTable = dal.GetPicture(TechnologyId);   return dTable;  } }}

TechnologyDAL层的方法

namespace BTAppDAL{ public class TechnologyDAL {  public DataTable GetList(int startPage, int pageSize, string where, string orderby)  {   string strSql = string.Format("SELECT a.TechnologyId,a.TechnologyName,a.Summarize,a.Effect,a.MainPoint,a.AppropriateArea,a.Attention,a.CreateTime,a.CreatUser,a.UpdateTime,b.Name FROM Technology AS a \n" +    "left join Sys_DepInfo AS b ON a.Depinfo_Id=b.Id \n" +    "where a.IsActive='1' and {0} ", where);   string proc = "proc_CommonPagerWithStatement";   SqlConnection con = SqlDbHelper.Connection;   SqlParameter[] sp = { new SqlParameter("@intStartIndex", startPage),          new SqlParameter("@intPageSize", pageSize),         new SqlParameter("@varStatement", strSql),          new SqlParameter("@varSortExpression", orderby+" DESC") };   DataTable dt = SqlDbHelper.GetDataSet(proc, sp, con);   return dt;  }  public int GetCountList(string where)  {   int countRecord = 0;   string strSql = string.Format("select COUNT(TechnologyId) as countRecord from(SELECT a.TechnologyId,a.TechnologyName,a.Summarize,a.Effect,a.MainPoint,a.AppropriateArea,a.Attention,a.CreateTime,a.CreatUser,a.UpdateTime,b.Name FROM Technology AS a \n" +    "left join Sys_DepInfo AS b ON a.Depinfo_Id=b.Id \n" +    "where a.IsActive='1' and {0} ) as c", where);   SqlConnection con = SqlDbHelper.Connection;   try   {    if (con.State == System.Data.ConnectionState.Closed)     con.Open();    DataTable dt = SqlDbHelper.GetDataTable(strSql);    if (dt.Rows.Count > 0)     countRecord = int.Parse(dt.Rows[0]["countRecord"].ToString());   }   catch (Exception)   {    throw;   }   finally   {    if (con.State == ConnectionState.Open)    {     con.Close();    }   }   return countRecord;  }  public DataTable GetModel(string TechnologyId)  {   string strSql = string.Format("SELECT a.TechnologyId,a.TechnologyName,a.Summarize,a.Effect,a.MainPoint,a.AppropriateArea,a.Attention,a.CreateTime,a.CreatUser,a.UpdateTime,b.Name FROM Technology AS a \n" +    "left join Sys_DepInfo AS b ON a.Depinfo_Id=b.Id \n" +    "where a.IsActive='1' and a.TechnologyId = '{0}' ", TechnologyId);   DataTable dataTable = SqlDbHelper.GetDataTable(strSql);   return dataTable;  }  public DataTable GetPicture(string TechnologyId)  {   string strSql = string.Format("SELECT TOP 5 a.Files_Id,a.Files_Name,a.Files_Path FROM dbo.Com_Files AS a \n" +    "LEFT JOIN dbo.Technology AS b ON a.ForeignKey_Id=b.TechnologyId \n" +    "WHERE b.IsActive=1 and a.ForeignKey_Id = '{0}' ", TechnologyId);   DataTable dataTable = SqlDbHelper.GetDataTable(strSql);   return dataTable;  } }}

ExpertInfoBLL 层的方法

 public DataTable GetDepInfo()  {   DataTable dTable = dal.GetDepInfo();   return dTable;  }

ExpertInfoDAL层的方法

 public DataTable GetDepInfo()  {   try   {    StringBuilder str = new StringBuilder(@"SELECT Id,Name FROM dbo.Sys_DepInfo WHERE Is_Active='1' AND DepinfoType='1'");    DataTable data = SqlDbHelper.GetDataTable(str.ToString());    if (data.Rows.Count > 0)    {     return data;    }    else    {     return null;    }   }   catch (Exception)   {    return null;   }  }

在页面加载的时候调用DropDownListDataBind()方法
触发RadioButtonList的点击事件

 protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)  {    string Id;    Id = RadioButtonList1.SelectedValue;    GetDataBind(Id);  }

既可以实现点击某个单选按钮,并触发事件。

以上是"ASP.NET中RadioButtonList绑定后台数据后触发点击事件怎么用"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

数据 事件 方法 后台 内容 按钮 数据库 篇文章 页面 不同 价值 兴趣 前台 小伙 小伙伴 控件 文件 时候 更多 知识 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网科技公司 互联网科技公司起名 互联网科技保险 科技互联网技术 上海喔噻互联网科技 青岛中康互联网医疗科技有限公司 福州新华互联网科技学校 知乎 现代互联网科技股 贵州叶脉互联网科技有限公司所属行业 苏州五指互联网络科技有限 互联网科技革命什么开始 互联网科技商业 允成互联网科技有限公司融资 科技赋能视角下互联网保险发展 启辰互联网科技 广州百诚互联网科技有限公司官网 宇信科技在杭州互联网排第几 安徽零酒互联网科技有限公司 亚光科技低轨卫星互联网 六子台科技互联网展会 中关村互联网 科技集团 金融科技与互联网金融 万易互联网科技有限公司 深圳期待互联网科技 新华互联网科技校企合作 互联网科技博主是什么意思 哈尔滨新华互联网科技学院 想开互联网科技公司怎么样 河南住房之家互联网科技 深圳互联网科技园地址
0