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

 更新时间:2016年05月11日 10:31:45   作者:wangjingjing1014  
这篇文章主要介绍了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);
  }

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

以上就是本文的全部内容,希望对大家的学习有所帮助。

相关文章

  • ASP.NET MVC实现下拉框多选

    ASP.NET MVC实现下拉框多选

    这篇文章介绍了ASP.NET MVC实现下拉框多选的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-09-09
  • 浅谈ASP.NET Core 2.0 部分视图(译)

    浅谈ASP.NET Core 2.0 部分视图(译)

    本篇文章主要介绍了浅谈ASP.NET Core 2.0 部分视图(译),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-11-11
  • ASP.NET数据绑定之DataList控件实战篇

    ASP.NET数据绑定之DataList控件实战篇

    这篇文章主要为大家介绍了ASP.NET数据绑定中的DataList控件,DataList控件以表的形式呈现数据,通过该控件,您可以使用不同的布局来显示数据记录,对DataList控件感兴趣的小伙伴们可以参考一下
    2016-01-01
  • ASP.NET开发中经常用到10款工具软件介绍

    ASP.NET开发中经常用到10款工具软件介绍

    从事.NET开发也好几年了,工作过程中积累一些软件工具,分享给大家,排名不分先后,希望对大家有所帮助。
    2016-04-04
  • asp.net使用ajaxFileUpload插件上传文件(附源码)

    asp.net使用ajaxFileUpload插件上传文件(附源码)

    本文详细讲解了asp.net使用ajaxFileUpload插件上传文件,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-12-12
  • 通用 HTTP 签名组件的另类实现方式

    通用 HTTP 签名组件的另类实现方式

    这篇文章主要介绍了通用 HTTP 签名组件的另类实现方式,实现思路大概是采用链式调用的方式,使得签名的步骤可以动态拼凑组合,本文结合实例代码给大家介绍的非常详细,需要的朋友可以参考下
    2022-09-09
  • 在 .NET 中使用 FixedTimeEquals 应对计时攻击的例子

    在 .NET 中使用 FixedTimeEquals 应对计时攻击的例子

    在计算机安全中,计时攻击(Timing attack)是旁道攻击 (Side-channel attack) 的一种,而旁道攻击是根据计算机处理过程发出的信息进行分析,这篇文章主要介绍了在 .NET 中使用 FixedTimeEquals 应对计时攻击,需要的朋友可以参考下
    2022-06-06
  • asp.net 删除MFC单文档默认菜单栏的两种方法

    asp.net 删除MFC单文档默认菜单栏的两种方法

    新建一个MFC单文档程序,默认都有四个菜单栏:文件、编辑、视图和帮助。怎么把这四个菜单栏删除掉呢?
    2010-03-03
  • asp.net 分页显示数据表的数据的代码

    asp.net 分页显示数据表的数据的代码

    asp.net显示第一页、上一页、下一页和最后一页的分页显示数据表的数据
    2010-03-03
  • ASP.NET MVC中图表控件的使用方法

    ASP.NET MVC中图表控件的使用方法

    这篇文章主要介绍了ASP.NET MVC中图表控件的使用方法,需要的朋友可以参考下
    2015-10-10

最新评论