Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the click event triggered by RadioButtonList binding background data in ASP.NET

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the ASP.NET RadioButtonList binding background data after the trigger click event how to use, the article is very detailed, has a certain reference value, interested friends must read it!

First, a RadioButtonList control is placed on the foreground page

.cs file background binding data

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 binds background data private void DropDownListDataBind () {ExpertInfoBLL bll = new ExpertInfoBLL (); DataTable dt = bll.GetDepInfo (); foreach (DataRow dr in dt.Rows) {RadioButtonList1.Items.Add (dr ["Name"]. ToString ()); / / read out the data of the database} 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) {/ / write and decode here and the result returned by the database TechnologyBLL bll = new TechnologyBLL (); string strWhere = "1x1"; if (Id! = "" & Id! = null) {strWhere + = string.Format ("and a.Depinfo_Id ='{0}'", Id);} AspNetPager1.RecordCount = bll.GetCountList (strWhere) / / bind data 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);} / / trigger event protected void RadioButtonList1_SelectedIndexChanged (object sender, EventArgs e) {string Id; Id = RadioButtonList1.SelectedValue depending on the id in which the radio button is selected GetDataBind (Id);}

The method of TechnologyBLL layer

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;}}

The method of TechnologyDAL layer

Namespace BTAppDAL {public class TechnologyDAL {public DataTable GetList (int startPage, int pageSize, string where, string orderby) {string strSql = string.Format ("SELECT a.TechnologyIdmema.TechnologyNamemema.Summarizemema.EffectMagica a.MainPointma.AppropriateAreaMainPointma.AttentionMa.CreateTimecoa.CreatUserfora.UpdateTimejingb.Name\ n" + "left join Sys_DepInfo AS b ON a.Depinfo_Id=b.Id\ n" + "where a.IsActivecards 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 FROM Technology AS a.) as 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 _ 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. Filespace 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.ForeignKeykeeper ID ='{0}'", TechnologyId); DataTable dataTable = SqlDbHelper.GetDataTable (strSql); return dataTable;}

The method of ExpertInfoBLL layer

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

The method of ExpertInfoDAL layer

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;}}

Call the DropDownListDataBind () method when the page is loaded

Click event that triggers RadioButtonList

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

It is possible to click a radio button and trigger an event.

The above is all the contents of this article entitled "how to trigger Click events after RadioButtonList binds background data in ASP.NET". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report