protected void Page_Load(object sender, EventArgs e) { DataList1.DataSourceID = "SqlDataSource3"; Label1.Text = DataList1.Items.Count.ToString(); } private SqlDataReader getReader() { //get connection string from web.config string strConnectionString = ConfigurationManager.ConnectionStrings["ASPNETDBConnectionString1"].ConnectionString; SqlConnection myConnect = new SqlConnection(strConnectionString); string strCommandText = "SELECT CategoryID, CatName from Category"; SqlCommand cmd = new SqlCommand(strCommandText, myConnect); myConnect.Open(); DataList1.DataBind(); // CommandBehavior.CloseConnection will automatically close connection SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); return reader; } protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { DataList1.DataSourceID = "SqlDataSource1"; if (RadioButtonList1.SelectedIndex == 0) { Session["catID"] = 1; } else if (RadioButtonList1.SelectedIndex == 1) { Session["catID"] = 2; } else if (RadioButtonList1.SelectedIndex == 2) { Session["catID"] = 3; } else if (RadioButtonList1.SelectedIndex == 3) { Session["catID"] = 4; } else if (RadioButtonList1.SelectedIndex == 4) { Session["catID"] = 5; } else { Session["catID"] = 8; } }
protected void Page_Load(object sender, EventArgs e) { if(!ispostback) { DataList1.DataSourceID = "SqlDataSource3"; Label1.Text = DataList1.Items.Count.ToString(); } }
SQLDataSource
DataList1.DataBind()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)