首页 > 编程 > .NET > 正文

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

2024-07-10 12:47:14
字体:
来源:转载
供稿:网友

本文实例为大家分享了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;  } }}            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表