This is a migrated thread and some comments may be shown as answers.

Evaluating controls, can this be done with Grid

3 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian McWilliams
Top achievements
Rank 1
Brian McWilliams asked on 04 May 2010, 09:16 PM
I am currently working on developing a time card entry application, and evaluating the Telerik ASP.NET Ajax controls.

I have spent the day trying to make the following work, however I have not had any success. Was wondering if you would be able to offer some suggestions?

Scenario:
I have a grid that is populated with data from a SQL query done in code server side (and this works ok). We need to be able to edit this data in grid. I have been trying to make this work in a FormTemplate.
a. Two of the columns (Job and Cost Code) should be drop down lists. They are from different data tables (We'll call them JobCode and CostCode for now) - and there is a foreign key relationship between these two tables.
b. On initial click of the Edit, I need it to:
    - Populate the job list
    - Select the appropriate job based on that row's data (JobID)
    - Populate the cost code list with those available for that job (based on JobID column and key relationship)
    - Select the appropriate cost code based on that rows data (CostCodeID)
c. If the Job SelectedIndex is changed, I need it to:
    - Populate the cost code list with those available for that job (based on JobID column and key relationship)
    - Select the first available item in the cost code drop down list

Any suggestions/ideas?

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 May 2010, 01:14 PM
Hello Brian,

Have a look at the code that I tried for same kind of scenario.

ASPX:
 
<FormTemplate> 
    <asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSource2" DataTextField="City" 
        DataValueField="City" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
    </asp:DropDownList> 
 
    <asp:DropDownList ID="DropDownList2" runat="server"
    </asp:DropDownList> 
</FormTemplate> 

In the ItemDataBound event, you can populate the 'City' DropDownList and set the SelectedValue.
C#:
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            GridEditFormItem edititem = (GridEditFormItem)e.Item; 
            DropDownList dr1 = (DropDownList)edititem.FindControl("DropDownList1"); 
            string id = edititem.GetDataKeyValue("CityID").ToString(); // Get the dataKeyValue 
            // Populate the DropdownList here 
            dr1.SelectedValue = id; // Set the SelectedValue for the City dropdownlist 
        } 
    } 


Now in the SelectedIndexChanged event, get the SelectedValue of City combo and query db by passing the value to populate the next dropdownlist control.
C#:
 
 
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        DropDownList drop1 = (DropDownList)sender; 
        GridEditFormItem edititem = (GridEditFormItem)drop1.NamingContainer; // EditForm 
        string city = drop1.SelectedValue;  // First dropdown's SelectedValue 
        DropDownList dr2 = (DropDownList)edititem.FindControl("DropDownList2"); 
 
        // Prepare the query by passing the "city" value 
        // Populate the second DropDownList 
        // Set SelectedValue property of dr2  
    } 


Regards,
Shinu.
0
Brian McWilliams
Top achievements
Rank 1
answered on 05 May 2010, 03:15 PM
Ok, I have it doing that for the first drop down list, but does not appear that the SelectedIndexChanged is getting fired. This is in VB.NET 2010 fyi.

Any thoughts?
0
Martin
Telerik team
answered on 11 May 2010, 07:51 AM
Hello Brian McWilliams,

If you have set the AutoPostBack = "true" and have wired the OnSelectedIndexChanged event of the first combo, then the event handler should be called. Could you provide the markup of the combos, as well as the relevant code behind code so I can inspect them further? Yet another option is to open a support ticket and send me a small sample project demonstrating your implementation.

I hope this helps,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Brian McWilliams
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brian McWilliams
Top achievements
Rank 1
Martin
Telerik team
Share this question
or