Home Ask Login Register

Developers Planet

Your answer is one click away!

Pauline Gail Mallari Chan February 2016

Selectedindexchanged does not show in the Web

I have DropDownList

Whenever Data selected from the DDL, It autofills the textboxes specified.

It does get the values but does not show in the web.

Here is asp.net

<table class="col-lg-12" align="center" width="900">  


    <td align="center" class="style2" valign="middle">  

    <td align="center" class="style4" valign="middle">  

    <td align="center" class="style4" valign="middle">  

    <td align="center" class="style4" valign="middle">  

<td class="style3"> 
   <asp:DropDownList ID="ddlName" runat="server" class="form-control" 
        onselectedindexchanged="ddlName_SelectedIndexChanged" Width="200px">    </asp:DropDownList>

   <td class="style5">  
  <asp:Label ID="lbID" runat="server" Width="200px"></asp:Label>  

   <td class="style5">  
  <asp:Label ID="lbPrice" runat="server" Width="200px"></asp:Label>  

  <td class="style5">  
  <asp:TextBox ID="Quantity" runat="server" Width="200px"></asp:TextBox>  

    <asp:Button ID="AddProduct" runat="server" style="color:White" 
        Text="Add Product" Width="200px" onclick="AddProduct_Click" /></td>  

ddlSelectedIndexChanged codes

protected void ddlName_SelectedIndexChanged(object sender, EventArgs e)
        string Name = ddlName.SelectedItem.Value;
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "SELECT Name, ProductID, Price FROM Products WHERE Name=@Name";


chapmanclay February 2016

I believe you should assign the Labels like this instead:

lbID.text = dr.GetInt32(1).ToString();
lbPrice.text = dr.GetDecimal(2).ToString();

Alternatively I would recommend looking into the DetailsView control for a more elegant, and easier in some cases, solution: DetailsVew Web Server Control

Post Status

Asked in February 2016
Viewed 3,862 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life