2014-09-10 3 views
0

나는 display_text를 표시하는 itemTemplate이있는 RadListBox가 있습니다. 테이블의 모든 데이터를 가져 오는 SQLDataSource를 사용하고 있습니다. 나는 ListBox 항목을 클릭하고 SelectedIndexChanged가 실행 된 후 C# 측에서 ID를 가져 와서 TextBox.Text를 변경하는 방법을 알고 싶습니다. 내 SQL 데이터 소스에 ID라는 열이 있으며 그 ID를 가져 와서 _carID에 설정하려고했습니다. int와 같은 것 _carID = LBcarDetail.FindControl ("ID"). 값; // (이 사용될 수있다 유사한 단지 예 올바르지 않습니다하지만 난 정확한 구문의 모르겠습니다.)Textbox.Text를 변경하려면 C#에서 RadListBox ID 값 가져 오기

<telerik:RadListBox ID="LBcarDetail" runat="server" DataSourceID="SqlDataSource1" AllowTransfer="true" AutoPostBackOnTransfer="true" OnSelectedIndexChanged="LBcarDetail_SelectedIndexChanged" 
    Height="700px" SelectionMode="Multiple" Width="615px" Skin="Outlook" EnableDragAndDrop="true" AllowReorder="true" AppendDataBoundItems="true" AutoPostBack="true"> 
    <ButtonSettings VerticalAlign="Top" ShowTransferAll="false" ShowTransfer="false" ShowDelete="true"></ButtonSettings> 
    <ItemTemplate> 
     <div style="border: 1px solid black; margin-right: auto; margin-left: auto;"> 
      <ul class="details1" style="list-style: none;"> 
       <li> 
        <label> 
         display_text: 
        </label> 
        <span> 
         <%# Eval("display_text") %></span> 
       </li> 
      </ul> 
     </div> 
    </ItemTemplate> 
</telerik:RadListBox> 

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:iConnectionString %>" 
    SelectCommand="SELECT * FROM [intranet].[dbo].[TableItems] ORDER BY sort_order"></asp:SqlDataSource> 

나는 다음과 같은 사용하여 표시 텍스트를 변경하려고 :

protected void LBcarDetail_SelectedIndexChanged(object sender, EventArgs e) 
     { 
    //int _carID = 2; //hardcoded 2 will change display text to the correct value for item with ID of 2 
    int _carID; //here is where I am trying to grab the ID of the listBox item that was selected 
    string _displayText; 

     using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["iConnectionString"].ToString())) 
     using (SqlCommand comm = new SqlCommand("sp_car_detail_get", conn)) 
     using (SqlDataAdapter adapter = new SqlDataAdapter(comm)) 
     { 
      comm.CommandType = CommandType.StoredProcedure; 
      comm.Parameters.Add(new SqlParameter("@id", id)); 

      DataSet ds = new DataSet(); 
      adapter.Fill(ds); 
      foreach (DataRow r in ds.Tables[0].Rows) 
      { 
       _displayText = r["display_text"].ToString(); 

       tbDisplayText.Text = _displayText; 
      } 
     } 
} 

답변

0

은 내가 RadListBox에 DataValueField = "ID"를 추가하고 값을 얻기 위해 이것을 사용 :

int id = Convert.ToInt32(LBcarouselDetail.SelectedItem.Value);