The example of this article shared the RadioButtonList binding background data, triggering the Click event method
First, the front page places a RadioButtonList control
<asp:radiobuttonlist runat= "Server" id= "RadioButtonList1" borderstyle= "None" repeatcolumns= "3" cssclass=
"" repeatlayout= "Flow" autopostback= "true" onselectedindexchanged= "radiobuttonlist1_selectedindexchanged" >
</asp:RadioButtonList>
. 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 binding 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 ());//loop read data from database} this.
Radiobuttonlist1.datasource = DT; This.
Radiobuttonlist1.datatextfield = "Name"; This.
Radiobuttonlist1.datavaluefield = "Id"; This.
Radiobuttonlist1.repeatdirection = RepeatDirection.Horizontal; This.
Radiobuttonlist1.databind (); The private void Getdatabind (string Id) {//Here writes the decoding and the database returns the result 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); Bound 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); The event protected void Radiobuttonlist1_selectedindexchanged (object sender, EventArgs e) {string, based on the different IDs of the Select radio button
Id;
Id = RadioButtonList1.SelectedValue;
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 by)
{
datatable dtable = dal. GetList (StartPage, PageSize, where, by);
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 by) {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_DEP
Info 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; The 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.techn
Ologyid = ' {0} ', Technologyid);
DataTable datatable = Sqldbhelper.getdatatable (strSQL);
return dataTable; The 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} ' ", Technologyi
D);
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
triggering the RadioButtonList click event
protected void Radiobuttonlist1_selectedindexchanged (object sender, EventArgs e)
{
string Id;
Id = RadioButtonList1.SelectedValue;
Getdatabind (Id);
}
It is possible to click on a radio button and trigger an event.
The above is the entire content of this article, I hope to help you learn.