I am binding the DataGrid to a datasource at runtime. After binding I want to populate a listbox with the column headers from the datagrid. How can I reference the column headertext for each column in the datagrid and then add them to my listbox

In the ItemDataBound Event write following code VB.NET Dim i As Integer = 0 If e.Item.ItemType = ListItemType.Header Then For i = 0 To e.Item.Cells.Count -1 Me.ListBox1.Items.Add(e.Item.Cells(i).Text) Next End If C# if (e.Item.ItemType== ListItemType.Header) { for(int i = 0; i <= e.Item.Cells.Count-1 ; i++) { this.ListBox1.Items.Add(new ListItem(e.Item.Cells[i].Text)); } }

How to force the max no. of characters in a multiline TextBox using RegularExpressionValidator

<asp:TextBox id=’TextBox1′ style=’Z-INDEX: 101; LEFT: 0px; POSITION: absolute; TOP: 112px’ runat=’server’ TextMode=’MultiLine’></asp:TextBox> <asp:RegularExpressionValidator id=’RegularExpressionValidator1′ style=’Z-INDEX: 102; LEFT: 216px; POSITION: absolute; TOP: 112px’ runat=’server’ ErrorMessage=’MaxLength is 20′ ControlToValidate=’TextBox1′ ValidationExpression=’^\w{1,20} > </asp:RegularExpressionValidator>

What is the best place to store Database connection string?

In Web.Config, you would add a key to the AppSettings Section: <appSettings> <add key=’MyDBConnection’ value=’server=<ServerName>;uid=<Username>;pwd=;database=<DBName>’ /> </appSettings> Example : <add key=’ConnectionString’ value= ‘Server=localhost;uid=sa;pwd=;database=northwind’ /> Then, in your ASP.Net application – just refer to it like this: Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings(‘ConnectionString’))

How to check if the Dataset has records

VB.NET if ds.Tables(0).Rows.Count= 0 then ’No record else ’Record Found end if C# if (ds.Tables[0].Rows.Count == 0 ) { //No record } else { //Record Found }