本文实例为大家分享了RadioButtonList绑定后台数据,触发点击事件的方法
首先前台页面放置一个RadioButtonList 控件
<asp:RadioButtonList runat="server" ID="RadioButtonList1" BorderStyle="None" RepeatColumns="3" CssClass="" RepeatLayout="Flow" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"> </asp: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); }
既可以实现点击某个单选按钮,并触发事件。
以上就是本文的全部内容,希望对大家的学习有所帮助。
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月30日
2024年11月30日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]