How to display multiple spaces in a dropdownlist

<asp:DropDownList id=’DropDownList1′ runat=’server’></asp:DropDownList> VB.NET Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ’Put user code to initialize the page here Dim i As Integer For i = 0 To 10 DropDownList1.Items.Add(‘Item Number’ + SpaceDDL(10) + i.ToString) Next End Sub Private Function SpaceDDL(ByVal numberOfSpaces As Integer) As String Dim Spaces As String Dim i As Integer For i = 0 To numberOfSpaces Spaces &= ‘ ‘ Next Return Server.HtmlDecode(Spaces) End Function C# private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here for(int i = 0 ;i<=10;i++) { DropDownList1.Items.Add(‘Item Number’ + SpaceDDL(10) + i.ToString()); } } string SpaceDDL(int numberOfSpaces ) { string Spaces=”; for(int i = 0 ;i<=numberOfSpaces;i++) { Spaces += ‘ ‘; } return Server.HtmlDecode(Spaces); }

How to change server control backcolor from a variable

<asp:TextBox id=’TextBox1′ BackColor =<%#colCon.ConvertFromString(bgcolor)%> runat=’server’> </asp:TextBox> VB.NET Protected colCon As New System.Drawing.ColorConverter Protected bgcolor As String = ‘#556600’ ’In Page_Load Page.DataBind() C# protected System.Drawing.ColorConverter colCon =new System.Drawing.ColorConverter(); protected string bgcolor = ‘#556600’; //In Page_Load Page.Databind();

How to display data in Textboxes using DataSet

Product ID : <asp:TextBox id=’TextBox1′ style=’Z-INDEX: 101; LEFT: 80px; POSITION: absolute; TOP: 64px’ runat=’server’></asp:TextBox> Product Name:<asp:TextBox id=’TextBox2′ style=’Z-INDEX: 102; LEFT: 80px; POSITION: absolute; TOP: 112px’ runat=’server’></asp:TextBox> VB.NET ’Populate the DataSet ’… ’Display in TextBoxes using Column Name TextBox1.Text = ds.Tables (0).Rows(0)(‘ProductId’).ToString (); TextBox2.Text =ds.Tables (0).Rows(0)(‘ProductName’).ToString (); ’Display in TextBoxes using Column Index TextBox1.Text = ds.Tables (0).Rows(0)(0).ToString (); TextBox2.Text =ds.Tables (0).Rows(0)(1).ToString (); C# //Populate the DataSet //… //Display in TextBoxes using Column Name TextBox1.Text = ds.Tables [0].Rows[0][‘ProductId’].ToString (); TextBox2.Text =ds.Tables [0].Rows[0][‘ProductName’].ToString (); //Display in TextBoxes using Column Index TextBox1.Text = ds.Tables [0].Rows[0][0].ToString (); TextBox2.Text =ds.Tables [0].Rows[0][1].ToString ();

How to display data in Textboxes using DataReader

Id : <asp:TextBox id=’TextBox1′ style=’Z-INDEX: 102; LEFT: 128px; POSITION: absolute; TOP: 32px’ runat=’server’></asp:TextBox> Name : <asp:TextBox id=’TextBox2′ style=’Z-INDEX: 103; LEFT: 128px; POSITION: absolute; TOP: 72px’ runat=’server’></asp:TextBox> VB.NET Dim cn As SqlConnection Dim cmd As SqlCommand Dim rdr As SqlDataReader Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ’ Put user code to initialize the page here Try cn = New SqlConnection(‘server=localhost;uid=sa;pwd=;database=northwind’) cmd = New SqlCommand(‘select * from Products where productid =1’, cn) cn.Open() rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection) rdr.Read() TextBox1.Text = rdr(‘ProductId’).ToString() TextBox2.Text = rdr(‘ProductName’).ToString() Catch ex As Exception Response.Write(ex.Message.ToString()) Finally rdr.Close() cn.Close() End Try End Sub C# SqlConnection cn ; SqlCommand cmd ; SqlDataReader rdr ; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here try { cn = new SqlConnection(‘server=localhost;uid=sa;pwd=;database=northwind’); cmd = new SqlCommand( ‘select * from Products where productid=1 ‘, cn); cn.Open(); rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection ); rdr.Read (); TextBox1.Text =rdr[‘ProductId’].ToString (); TextBox2.Text =rdr[‘ProductName’].ToString (); } catch (Exception ex) { Response.Write (ex.Message.ToString ()); } finally { rdr.Close(); cn.Close(); } }