I am using the following code to populate a DropDownList with the records existing in a database (the DropDownList gets populated with a list of different company names):
<script language="VB" runat="server">
Sub Page_Load(obj As Object,ea As EventArgs)
If Not(Page.IsPostBack) Then
Dim objDS As DataSet
Dim objConn As SQLConnection
Dim objDapter As SQLDataAdapter
objConn=New SQLConnection("Server=(local)........."
objDapter=New SQLDataAdapter("SELECT CName,CCode,CName,CCode FROM Company",objConn)
objDS=new DataSet()
objDapter.Fill(objDS,"Comp"
cname.DataSource=objDS.Tables("Comp".DefaultView
cname.DataBind()
End If
End Sub
</script>
<form runat="server">
<aspropDownList id="cname" AutoPostBack="true" DataTextField="CName" DataValueField="CCode" OnSelectedIndexChanged="selectEName" runat="server">
</aspropDownList>
</form>
Now, as expected, the DropDownList will be populated with the different company names.Even the 1st option that will be displayed in the DropDownList will be a company name. The HTML source code when viewed will be something like this:
<select.....>
<option value="C1">Company1</option>
<option value="C2">Company2</option>
<option value="C3">Company3</option>
<option value="C4">Company4</option>
</select>
However, I want that the 1st option in the DropDownList should be something like "Select Your Company" & then only the different company names should be listed. For eg. the HTML source code should be something like this:
<select.....>
<option>Select Your Company</option>
<option value="C1">Company1</option>
<option value="C2">Company2</option>
<option value="C3">Company3</option>
<option value="C4">Company4</option>
</select>
How do I do this in ASP.NET?
Thanks,
Arpan
<script language="VB" runat="server">
Sub Page_Load(obj As Object,ea As EventArgs)
If Not(Page.IsPostBack) Then
Dim objDS As DataSet
Dim objConn As SQLConnection
Dim objDapter As SQLDataAdapter
objConn=New SQLConnection("Server=(local)........."
objDapter=New SQLDataAdapter("SELECT CName,CCode,CName,CCode FROM Company",objConn)
objDS=new DataSet()
objDapter.Fill(objDS,"Comp"
cname.DataSource=objDS.Tables("Comp".DefaultView
cname.DataBind()
End If
End Sub
</script>
<form runat="server">
<aspropDownList id="cname" AutoPostBack="true" DataTextField="CName" DataValueField="CCode" OnSelectedIndexChanged="selectEName" runat="server">
</aspropDownList>
</form>
Now, as expected, the DropDownList will be populated with the different company names.Even the 1st option that will be displayed in the DropDownList will be a company name. The HTML source code when viewed will be something like this:
<select.....>
<option value="C1">Company1</option>
<option value="C2">Company2</option>
<option value="C3">Company3</option>
<option value="C4">Company4</option>
</select>
However, I want that the 1st option in the DropDownList should be something like "Select Your Company" & then only the different company names should be listed. For eg. the HTML source code should be something like this:
<select.....>
<option>Select Your Company</option>
<option value="C1">Company1</option>
<option value="C2">Company2</option>
<option value="C3">Company3</option>
<option value="C4">Company4</option>
</select>
How do I do this in ASP.NET?
Thanks,
Arpan