update controls in edit mode

6 posts, 1 answers
  1. Jugoslav
    Jugoslav avatar
    64 posts
    Member since:
    Mar 2011

    Posted 18 Mar 2014 Link to this post

    Hello,

    I have a combo box inside a GridTableView. It is populated on demand (Load on demand)
    I want to make that ComboBox the other two TextBox controls to be populated with appropriate data when the ComboBox's index is changed.
    How do i do that?

    Thank you so much 
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Mar 2014 in reply to Jugoslav Link to this post

    Hi Jugoslav,

    I guess you want to have a TextBox populated on the RadComboBox OnSelectedIndexChanged event in RadGrid edit mode. Please have a loo at the following code snippet.

    ASPX:
    <telerik:GridTemplateColumn HeaderText="CompanyName">
        <ItemTemplate>
            <%# Eval("CompanyName") %>
        </ItemTemplate>
        <EditItemTemplate>
            <telerik:RadComboBox ID="RadComboBox1" runat="server" EnableLoadOnDemand="true" AllowCustomText="true" ShowMoreResultsBox="true" MaxHeight="220px" AutoPostBack="true" Filter="StartsWith" OnItemsRequested="RadComboBox1_ItemsRequested" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
            </telerik:RadComboBox>
        </EditItemTemplate>
    </telerik:GridTemplateColumn>
    <telerik:GridTemplateColumn EditFormHeaderTextFormat="TextBox">
        <EditItemTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </EditItemTemplate>
    </telerik:GridTemplateColumn>

    C#:
    protected void RadComboBox1_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
    {
        RadComboBox combo = (RadComboBox)sender;
        String connstring = WebConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
        SqlConnection conn = new SqlConnection(connstring);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand("SELECT * from Customers WHERE CompanyName LIKE '" + e.Text + "%'", conn);
        DataTable data = new DataTable();
        conn.Open();
        try
        {
            adapter.Fill(data);
        }
        finally
        {
            conn.Close();
        }
        combo.DataSource = data;
        combo.DataTextField = "CompanyName";
        combo.DataValueField = "CompanyName";
        combo.DataBind();
    }
     
    protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox combo = (RadComboBox)sender;
        GridEditableItem edititem = (GridEditableItem)combo.NamingContainer;
        string selectedvalue = combo.SelectedValue;
        TextBox txt = (TextBox)edititem.FindControl("TextBox1"); //Access the TextBox
        txt.Text = selectedvalue;
    }

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jugoslav
    Jugoslav avatar
    64 posts
    Member since:
    Mar 2011

    Posted 19 Mar 2014 in reply to Princy Link to this post

    Unhandled exception at line 15, column 16485 in http://localhost:49573/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScripts_=;;System.Web.Extensions,+Version=4.0.0.0,+Culture=neutral,+PublicKeyToken= ....<br><br>0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.


    Any ideas why it happens?
  5. Jugoslav
    Jugoslav avatar
    64 posts
    Member since:
    Mar 2011

    Posted 19 Mar 2014 Link to this post

    protected void Medications_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
            {
                RadComboBox combo = (RadComboBox)sender;
                GridEditableItem edititem = (GridEditableItem)combo.NamingContainer;           
                TextBox BookTitleEdit = edititem.FindControl("BookTitleEdit") as TextBox;
                if (BookTitleEdit != null)
                {
                    BookTitleEdit.Text = "OK"; // combo.SelectedValue;
                }
            }

    Meaning, the combobox rises the event but the textbox control seems to be not found in the code. Thanks again
  6. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 24 Mar 2014 Link to this post

    Hi Jugoslav,

    Could you please elaborate more on what EditMode does the grid use? If it uses Batch I suggest moving the populating logic on the client(because if a postback is triggered from the combo the changes will be lost).

    Note that it would be best to provide us with the markup and code-behind of the page so we could examine the scenario. That would greatly facilitate us in providing a more precise answer.

    Regards,
    Angel Petrov
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
  7. Jugoslav
    Jugoslav avatar
    64 posts
    Member since:
    Mar 2011

    Posted 25 Mar 2014 in reply to Angel Petrov Link to this post

    Oh no the Princy's answer helped me to sort this thing out ... i marked his reply as answer already. 
    It was my mistake when i was testing his code refering TextBox instead RadTextBox ... as soon as i changed that it worked like a charm. 

    Thank you so much anyway
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017