Equals method will do object level comparison. Which means it will check if both objects are same or not. In your case DropDownList5.SelectedIndex
will give int
object, which you are comparing with typeof
other object, which will always return false, unless the typeof
is int
.
Since you are getting the result with the column names as COLUMN_NAME
and DATA_TYPE
, change your DropDownList
tag to include these column names. As,
<asp:DropDownList ID="DropDownList5" runat="server" DataSourceID="column_list_for_filter" DataTextField="COLUMN_NAME" DataValueField="DATA_TYPE" OnSelectedIndexChanged ="DropDownList5_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
Then you will get the DataType
of the column in DropDownList5.SelectedValue
, which is a string
. Then you can add the controls based on the DropDownList
selection by comparing SelectedValue
with the string
name of the DataType
. As,
protected void DropDownList5_SelectedIndexChanged(object sender, EventArgs e)
{
if(DropDownList5.SelectedValue == "decimal")
{
TextBox1.Text = dr.GetString(0);
}
else if(DropDownList5.SelectedValue == "int")
{
Label1.Text = dr.GetString(0);
}
else if(DropDownList5.SelectedValue == "varchar")
{
Button1.Text = dr.GetString(0);
}
}