2014-02-01 2 views
1

У меня есть скрипт, который я хочу показать значения в метке после отправки после того, как вы выбрали элемент из выпадающего списка. Когда я выбираю элемент из раскрывающегося списка, например «Apple», он покажет в ярлыке цену Apple. И если я выбираю в DROPDOWNLIST «Апельсин» на этикетке он будет показывать цену Orange». Любые идеи, как это сделать? Спасибо.Показать значения в ярлыке из выбранного элемента в выпадающем списке

это код ...

ContactDetalis. ASCX

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactDetails.ascx.cs" 
    Inherits="UserControl_ContactDetails" EnableViewState="false" %> 
    <style type="text/css"> 
     .auto-style1 { 
      width: 100%; 
     } 
     .auto-style2 { 
      width: 150px; 
     } 
     .auto-style3 { 
      width: 294px; 
     } 
     .auto-style4 { 
      width: 150px; 
      text-align: right; 
     } 
    </style> 
<table class="auto-style1"> 
    <tr> 
     <td class="auto-style4"> 
      <asp:Label ID="Label7" runat="server" Text="Klienti:"></asp:Label> 
     </td> 

     <td class="auto-style3"> 
      <asp:DropDownList ID="DropDownListKlienti" runat="server"> 
      </asp:DropDownList> 
     </td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td class="auto-style4"> 
      <asp:Label ID="Label1" runat="server" Text="Artikulli:"></asp:Label> 
     </td> 
     <td class="auto-style3"> 
      <asp:DropDownList ID="DropDownListArtikulli" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownListArtikulli_SelectedIndexChanged"> 
      </asp:DropDownList> 
     </td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td class="auto-style4"> 
      <asp:Label ID="Label2" runat="server" Text="Cmimi:"></asp:Label> 
     </td> 
     <td class="auto-style3"> 
      <asp:Label ID="LabelCmimi" runat="server"></asp:Label> 
      <asp:Label ID="Label3" runat="server" Text="lek"></asp:Label> 
     </td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td class="auto-style4"> 
      <asp:Label ID="Label4" runat="server" Text="Sasia:"></asp:Label> 
     </td> 
     <td class="auto-style3"> 
      <asp:TextBox ID="TextBoxSasia" runat="server" AutoPostBack="True" OnTextChanged="TextBoxSasia_TextChanged"></asp:TextBox> 
     </td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td class="auto-style4"> 
      <asp:Label ID="Label5" runat="server" Text="Vlera:"></asp:Label> 
     </td> 
     <td class="auto-style3"> 
      <asp:Label ID="LabelVlera" runat="server"></asp:Label> 
      <asp:Label ID="Label6" runat="server" Text="lek"></asp:Label> 
     </td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td class="auto-style2">&nbsp;</td> 
     <td class="auto-style3">&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td class="auto-style2">&nbsp;</td> 
     <td class="auto-style3">&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td class="auto-style2">&nbsp;</td> 
     <td class="auto-style3">&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td class="auto-style2">&nbsp;</td> 
     <td class="auto-style3">&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
</table> 

ContactDetalis.ascx.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

using System.Data.SqlClient; 
using System.Configuration; 
using System.Data; 

public partial class UserControl_ContactDetails : System.Web.UI.UserControl 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     if(Page.IsPostBack) 
     { 
      AddItems(); 

      //Retain the state of controls 
      DropDownListKlienti.Text = Request.Form[DropDownListKlienti.UniqueID]; 
      DropDownListArtikulli.Text = Request.Form[DropDownListArtikulli.UniqueID]; 
      LabelCmimi.Text = Request.Form[LabelCmimi.UniqueID]; 
      TextBoxSasia.Text = Request.Form[TextBoxSasia.UniqueID]; 
      LabelVlera.Text = Request.Form[LabelVlera.UniqueID]; 
     } 

     if(!IsPostBack) 
     { 
      AddItems(); 
     } 
    } 

    private void AddItems() 
    { 
     DataTable listaArtikujt = new DataTable(); 

     using (SqlConnection lidhje = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString)) 
     { 
      try 
      { 

       SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM [Artikujt]", lidhje); 
       adapter.Fill(listaArtikujt); 

       DropDownListArtikulli.DataSource = listaArtikujt; 
       DropDownListArtikulli.DataTextField = "Artikulli"; 
       DropDownListArtikulli.DataValueField = "Cmimi"; 
       DropDownListArtikulli.DataBind(); 

       LabelCmimi.Text = DropDownListArtikulli.SelectedValue.ToString(); 

      } 
      catch (Exception ex) 
      { 
       Response.Write("Gabim:" + ex.ToString()); 
      } 
     } 
    } 
    protected void DropDownListArtikulli_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     AddItems(); 
    } 
    protected void TextBoxSasia_TextChanged(object sender, EventArgs e) 
    { 
     LabelVlera.Text = TextBoxSasia.Text.ToString(); 
    } 
} 
+0

Ваша проблема непонятна. В чем проблема с вашим текущим кодом? Он считывает введенные значения. Вы спрашиваете, как получить цены, так как это не ясно из вашего вопроса. –

ответ

0

удалить AddItems(), и добавить к вашему select_changed код

protected void DropDownListArtikulli_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    LabelCmimi.Text = DropDownListArtikulli.SelectedValue.ToString(); 
} 
Смежные вопросы