Drop Down List Selected Value.URGENT!!

Posted by .Netlearner under ASP.NET on 10/30/2012 | Points: 10 | Views : 1536 | Status : [Member] | Replies : 1
Hello All,

i have the dropdown list which is loaded dynamically as follows,

<asp:DropDownList ID="ddl1" runat="server" CssClass="dropdown"></asp:DropDownList>

protected void Load()
{
try
{
con.Open();
cmd = new SqlCommand("eT_SP_SelectType", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Type", "Daily Class");

dr = cmd.ExecuteReader();
ddl1.Items.Add("--Select--");
ddl1.Items[0].Value = "0";
int i = 1;
while (dr.Read())
{
ddl1.Items.Add(dr[Name"].ToString());
ddl1.Items[i].Value = dr["ID"].ToString();
i++;
}
con.Close();
}
catch (Exception ex)
{
}
}

on loading i checked with breakpoint values are coreect.For Eg) Name:aaa ID:1, Name:bb ID=2

but while using the ddl.selectedvalue on another event such as a button click as follows,
cmd = new SqlCommand("eT_SP_Insert", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter parameter = cmd.Parameters.Add("ReturnValue", SqlDbType.Int);
parameter.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.AddWithValue("@Name", txtbatchname.Text);
cmd.Parameters.AddWithValue("@ID",Convert.ToInt64(ddl1.SelectedValue ));
the ddl1.Selectedvalue is showing thw SelectedItem.Text value instead of its id.Whats happening.Where am going wrong can anyone please guide me.URGENT please help




Responses

Posted by: Self-Innovator on: 10/30/2012 [Member] Bronze | Points: 25

Up
0
Down
try with changing this line in your code
cmd.Parameters.AddWithValue("@ID",Convert.ToInt64(ddl1.SelectedItem.Value )); 


Join Hands Change lives
Thanks & Regards
Straight Edge Society

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response