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">  

<tr>

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

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

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

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

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

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

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

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

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

ddlSelectedIndexChanged codes

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

Answers


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

Search




Leave an answer