I have a DropDownList Control populated with List of Items from SqlDataSource. The SqlDataSource QueryBuilder chooses the Column_Names from my Database Table.
If the DropDownList is provided with DataTextField="All_Columns" DataValueField="All_Columns" properties, The DropDownList_SelectedIndexChanged() retains the selected input text.
Current Issue: Whereas if the DropDownList is provided with DataTextField="All_Columns" DataValueField="DATA_TYPE" properties, the DropDownList_SelectedIndexChanged() does not retain the text based on the selected input. But it retains the first value from the list of items which satisfies the respective DATA_TYPE present in an Index.
Solution Required: How to Retain the selected input text based on the DATA_TYPE property ? I tried storing the Session["DDLValue"] = DropDownList.SelectedItem.Text but it always retains the first value from the list of items which satisfies the respective DATA_TYPE present in an Index.
i.e. if i choose "e" from The following DropDownList inputs the value retained in DropDownList is **"d"
How to retain "e" i.e. selected text with DATA_TYPE Property.**
COLUMN_NAME DATA_TYPE
a decimal
b decimal
c decimal
d int
e int
f varchar
g varchar
h varchar
i varchar
j varchar
My aspx code:
<asp:DropDownList ID="DropDownList5" runat="server" DataSourceID="SqlDatasource1" DataTextField="All_Columns" DataValueField="DATA_TYPE" OnSelectedIndexChanged ="DropDownList5_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDatasource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDatabaseConnectionString %>" SelectCommand="SELECT COLUMN_NAME AS 'All_Columns', DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_NAME = 'MyTable')">
</asp:SqlDataSource>
C# Code:
protected void DropDownList5_SelectedIndexChanged(object sender, EventArgs e)
{
Session["DDLValue"] = DropDownList5.SelectedValue;
/***Retains wrong text***/
}