I have a RadListBox which has an itemTemplate that displays the display_text. I am using a SQLDataSource which grabs all of the data from a table. I would like to know how I can get the ID from the C# side to change the TextBox.Text after I click on an listBox item and SelectedIndexChanged is fired. My SQL datasource has a column named ID and I wanted to grab that ID and set it in the _carID. Something like int _carID = LBcarDetail.FindControl("ID").Value; //(this is not correct, just an example of something similar that may be used but I am not sure of the exact syntax.)

<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>
        <div style="border: 1px solid black; margin-right: auto; margin-left: auto;">
            <ul class="details1" style="list-style: none;">
                        <%# Eval("display_text") %></span>

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

I am trying to change the display text using the following:

    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();
            foreach (DataRow r in ds.Tables[0].Rows)
                _displayText = r["display_text"].ToString();

                tbDisplayText.Text = _displayText;

Related posts

Recent Viewed