RadioButtonList binding background data, triggering click events

Source: Internet
Author: User

First, a RadioButtonList control is placed on the foreground page

<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 the data from 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)
{
Here write the decode 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);
Binding 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);
}

Triggers an event based on the different IDs of the selected radio buttons
protected void Radiobuttonlist1_selectedindexchanged (object sender, EventArgs e)
{
String Id;
Id = RadioButtonList1.SelectedValue;
Getdatabind (ID);
}

}
}

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

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

Method of EXPERTINFOBLL Layer

Public DataTable Getdepinfo ()
{
DataTable dtable = dal. Getdepinfo ();
return dtable;
}

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 loads

Trigger a RadioButtonList Click event

protected void Radiobuttonlist1_selectedindexchanged (object sender, EventArgs e)
{
String Id;
Id = RadioButtonList1.SelectedValue;
Getdatabind (ID);
}

Can be achieved by clicking on a radio button and triggering an event

RadioButtonList binding background data, triggering click events

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.