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

[Solved] FormTemplate DropDownList And ItemCommand

3 Answers 261 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rhesa-Moile
Top achievements
Rank 1
Rhesa-Moile asked on 09 Apr 2009, 10:57 AM
Hello,

I have a radgrid with a detailedtable in it. Also I have a Custom FormTemplate.

When I press the 'add new record' button, I would like the form to fill with the apropriate info and have the dropdownlists on the value that was saved in the database. For some reason I can not use 'selectedvalue = <% ... %>' I get the error that it can not be set declarativily.

So I added a onItemCommand function (see below). This works fine for the dropdownlists, but now the textboxex in the custom form are empty. Is there any other way to select an item in the dropdownlists, or is it possible to get the values for the textboxex from the OwnerTableView or something?

I hope someone can help me, couse it drives me insane!!

        protected void grdAccounts_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) {
            if (e.CommandName == RadGrid.EditCommandName) {
                string sAccountType = grdAccounts.MasterTableView.DataKeyValues[e.Item.ItemIndex]["AccountType"].ToString();
                e.Canceled = true;
                e.Item.OwnerTableView.InsertItem();

                GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
                ((DropDownList)(insertedItem.FindControl("drpAccountType"))).SelectedValue = sAccountType;
            }
        }

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Apr 2009, 11:49 AM
Hello Rhesa,

You can try accessing the controls in Item_DataBound instead of ItemCommand. Try out the following code snippet.

[CS]
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item.OwnerTableView.Name == "TableName"
    { 
        if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridEditFormInsertItem) 
        { 
            GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item; 
            DropDownList dropdown = (DropDownList)item.FindControl("Dropdown"); //Get the dropdownlist 
            dropdown.SelectedValue = "Text2"
        }   
    } 

Thanks,
Shinu.
0
Rhesa-Moile
Top achievements
Rank 1
answered on 09 Apr 2009, 01:22 PM
I am sorry, but this dont seem to work for me. e.Item.OwnerTableView.Name is allways empty and whats more... e.Item.OwnerTableView.IsItemInserted is never true. I would like to select the right dropdownitem in the formtemplate when the user starts editing the record.

Any more suggestions?

Tnx
Rhesa
0
Shinu
Top achievements
Rank 2
answered on 15 Apr 2009, 08:16 AM
Hi,

I guess you have not set the Name property for the Detail table. Try setting it in the aspx as shown below.

ASPX:
 
 <DetailTables> 
    <telerik:GridTableView runat="server"  Caption="Detail"   Name="TableName"   > 
                        


Thanks
Shinu
Tags
Grid
Asked by
Rhesa-Moile
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Rhesa-Moile
Top achievements
Rank 1
Share this question
or