ASP.NET中RadioButtonList绑定后台数据后触发点击事件
本文实例为大家分享了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); }
既可以实现点击某个单选按钮,并触发事件。
以上就是本文的全部内容,希望对大家的学习有所帮助。
相关文章
- 这篇文章主要为大家介绍了python编程使用PyQt5如何创建按钮及触发点击事件的示例解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步...2021-10-29
- 这篇文章主要介绍了C#中WPF ListView绑定数据的实例详解的相关资料,希望通过本文能帮助到大家,让大家理解掌握这部分内容,需要的朋友可以参考下...2020-06-25
- 本文主要分享了jquery实现输入框实时输入触发事件的代码,代码简单易懂,需要的朋友一起来看下吧...2017-01-09
- 下面小编就为大家带来一篇JS判断键盘是否按的回车键并触发指定按钮点击操作的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2017-02-19
- 下面小编就为大家带来一篇浅谈键盘上回车按钮的js触发事件。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2017-02-19
- 这篇文章主要为大家详细介绍了微信小程序实现页面监听自定义组件的触发事件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-11-02
asp.net datalist绑定数据后可以上移下移实现示例
这篇文章主要介绍了asp.net datalist绑定数据后可以上移下移的示例代码,需要的朋友可以参考下...2021-09-22ASP.NET服务器端控件RadioButtonList,DropDownList,CheckBoxList的取值、赋值用法
这三个控件都有一个Items集合,可以用 RepeatLayout 和 RepeatDirection 属性来控制列表的呈现形式...2021-09-22ASP.NET中RadioButtonList绑定后台数据后触发点击事件
这篇文章主要介绍了ASP.NET中RadioButtonList绑定后台数据后触发点击事件的相关资料,感兴趣的小伙伴们可以参考一下...2021-09-22如何为CheckBoxList和RadioButtonList添加滚动条
这篇文章主要介绍了为CheckBoxList和RadioButtonList添加滚动条的方法,感兴趣的小伙伴们可以参考一下...2021-09-22- 这篇文章主要为大家详细介绍了ASP.NET控件之RadioButtonList的使用方法,感兴趣的小伙伴们可以参考一下...2021-09-22
RadioButtonList绑定图片及泛型Dictionary应用
读取站点某一目录的图片,需要掌握LINQ与泛型Dictionary<TKey,TValue>的使用,本文将介绍RadioButtonList绑定图片的实现,感兴趣的朋友可以了解下,或许对你有所帮助...2021-09-22实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上
一直想实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上。此功能就是当鼠标经过时RadioButtonList或CheckBoxList每一个Item时,让Item有特效显示,离开时,恢复原样有演示动画,感兴趣的朋友可以了解下啊...2021-09-22ASP.NET MVC中jQuery与angularjs混合应用传参并绑定数据
这篇文章主要介绍了ASP.NET MVC中jQuery与angularjs混合应用传参并绑定数据,需要的朋友可以参考下...2021-09-22.net控件dropdownlist动态绑定数据具体过程分解
一、在页面初始化时候将集合绑定到DropDownList;二、在页面初始化的时候向DropDownList添加数据;三、将DataReader读取的数据动态绑定到DropDownList等等...2021-09-22读取XML并绑定至RadioButtonList实现思路及演示动画
读取XML的文档,可以使用System.Data.DataSet类别中的ReadXml()方法,在aspx网页上拉一个RadioButtonList控件,用来显示XML的数据,接下来,用DataSet去读取刚才写好的获取XML文件的属性,即可完成...2021-09-22- 这篇文章主要介绍了如何将数据绑到gridview然后导成excel,需要的朋友可以参考下...2021-09-22
javascript判断是否有对RadioButtonList选项选择
写个Javascript来判断是否有对RadioButtonList选项选择,附动画演示,感兴趣的朋友可以了解下,希望对您们有帮助...2021-09-22ASP.NET中 RadioButtonList 单选按钮组控件的使用方法
本文主要简单介绍RadioButtonList控件的常见属性和使用方法,希望对大家有所帮助。...2021-09-22ASP.NET中的DataGridView绑定数据和选中行删除功能具体实例
废话就不多说了,都说.NET是托控件的,我就托给你们看,这个博文主要讲 DataGridView 的数据绑定,和选中行删除功能...2021-09-22