We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Set default value on add row

Hello,

I have i row with a Dropdown  EditItemTemplate in one column and 3 TextBox in other 3 columns always as EditItemTemplate. I need to set a dynamic default value for each textbox when i change the selected item in the dropdown. How i can do it? I tried with record.setValue on selectindexchanged event but it doesn't work.

An another question: How i can find the ItemTemplate control with FindControl property? I tried this ggc.FindControl("id") but i don't find my control

Thanks,
Fabio

1 Reply

YO Yogeshwaran Syncfusion Team August 24, 2012 10:02 AM UTC

Hi Fabio,

 

Thanks for using Syncfusion products.

 

Query #1:  I need to set a dynamic default value for each textbox when change the selected item in the dropdown. How can i do it?

 

 1)This can achieved in dropdown “OnSelectedIndexChanged” event. Please find the following code snippet.

 

protected void drop1_TextChanged(object sender, EventArgs e)

{

Control control = ((DropDownList)sender).NamingContainer.Parent;

TextBox IDtext =  (TextBox)FindControlRecursive(control, "ID");

if (IDtext != null)

IDtext.Text = list[((DropDownList)sender).SelectedIndex - 1].ID.ToString();

TextBox CurrencyText = (TextBox)FindControlRecursive(control, "Currency");

if (CurrencyText != null)

CurrencyText.Text = list[((DropDownList)sender).SelectedIndex - 1].Currency.ToString();

TextBox TelephoneText = (TextBox)FindControlRecursive(control, "Telephone");

if (TelephoneText != null)

TelephoneText.Text = list[((DropDownList)sender).SelectedIndex - 1].Telephone.ToString();

 

}

 

 

 2) In some asp.net controls don’t have default autopostback as true . So we have to enable AutoPostBack as true to trigger postback event. Please find the code snippet.

 

                                 <asp:DropDownList ID="drop1" runat="server" EnableViewState="true" OnSelectedIndexChanged="drop1_TextChanged" AutoPostBack="true">

 

  Query #2: How  can i find the ItemTemplate control with FindControl property?

 

             You can use custom method to find your control . please find the method

 

Control FindControlRecursive(Control parent, string id)

{

                                    Control ctrl = parent.FindControl(id);

                    if (ctrl == null && parent.HasControls())

          {

 foreach (Control c in parent.Controls)

{             

                                                         ctrl = FindControlRecursive(c, id);

                        if (ctrl != null) return ctrl;

                }

          }

     return ctrl;

}

 

 

For your convenience , we have created the sample and the same can be downloaded from below link.

 

Template.zip

 

Please let us know if you have any concerns.

 

Regards,

Yogesh R


Loader.
Live Chat Icon For mobile
Up arrow icon