continuation od Databinding
-
public class WebForm5 : System.Web.UI.Page { protected System.Web.UI.WebControls.RadioButtonList Radiobuttonlist1; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; protected System.Web.UI.WebControls.Label Label2; protected System.Web.UI.WebControls.DataGrid DataGrid1; protected System.Web.UI.WebControls.Label Label1; private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { Collections(); } } void Collections() { SqlConnection con=new SqlConnection("server=KHWA73R;database=NorthWind;user id=sa;password=sa"); SqlCommand cmd=new SqlCommand("Select TOP 10 CustomerID,CompanyName from Customers order by CompanyName ",con); SqlDataAdapter adpater =new SqlDataAdapter(cmd); DataSet sets=new DataSet(); try { con.Open(); adpater.Fill(sets); Radiobuttonlist1.DataSource =cmd.ExecuteReader(); Radiobuttonlist1.DataBind(); DataGrid1.DataBind(); } catch(InvalidOperationException ioe) { Console.WriteLine("Exception in the reader " + ioe.StackTrace); } catch(NullReferenceException nre) { Console.WriteLine("exception in null" + nre.ToString()); } finally { con.Close(); } } // Put user code to initialize the page here #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_Click(object sender, System.EventArgs e) { SqlConnection conn=new SqlConnection("server=KHWA73R;database=NorthWind;user id=sa;password=sa"); string strSelect=("SELECT CustomerID,OrderID FROM Orders" + " WHERE CustomerID = 'VINET' " + Radiobuttonlist1.SelectedItem.Value + "ORDER BY OrderID"); SqlCommand mycmd=new SqlCommand(strSelect,conn); //SqlDataReader readers=new SqlDataReader(mycmd); try { conn.Open(); // readers=mycmd.ExecuteReader(); DataGrid1.D