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.
Unfortunately, activation email could not send to your email. Please try again.

Set default value on add row

Thread ID:

Created:

Updated:

Platform:

Replies:

104288 Jul 8,2012 10:24 AM Aug 24,2012 06:02 AM ASP.NET Web Forms (Classic) 1
loading
Tags: GridGroupingControl
Fabio
Asked On July 8, 2012 10:24 AM

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

Yogeshwaran [Syncfusion]
Replied On August 24, 2012 06:02 AM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;