There is a dropdwon in my web page and a "Save' button:
HTML:
<asp:DropDownList ID="DType" runat="server" Width="80%"></asp:DropDownList>
<asp:Button ID="BOk" runat="server" Text="Save" OnClick="BOk_Click"/>
c#:
protected void BindType()
{
string type = "TYPE10";
string CommandText = "select value from Table1 where name = '" + type + "'";
DType.DataSource = DataManager.DatabaseManager.GetOrCreateConnection(DataManager.DatabaseManager.ConnectionType.MySQL).GetData(CommandText);
DType.DataTextField = "Value";
DType.DataValueField = "Value";
DType.DataBind();
DType.Items.Insert(0, new ListItem("--Select--", "0"));
}
protected void BOk_Click(object sender, EventArgs e)
{
string CommandText = "INSERT into Table2(ValueType) values('" + DType.SelectedValue + "')";
DataManager.DatabaseManager.GetOrCreateConnection(DataManager.DatabaseManager.ConnectionType.MySQL).ExecuteNonQueryCommand(CommandText, null);
}
When I click on "Save" Button to save the "Dropdown selected value". Everytime It saves "0" in place of selected value.
I am saving the selected value, but then too its saving '0' in Database table.
I think it is unable to select the Dropdown value. Therefore it saves 0
i.e., everytime it executes below line:
DType.Items.Insert(0, new ListItem("--Select--", "0"));
Please reply how to solve it using my code.