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

[Solved] Help me!

5 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dao
Top achievements
Rank 1
Dao asked on 22 May 2009, 03:09 AM
Operations with MS DropDownList in EditItemTemplate of GridTemplateColumn
After clicking edit, the data in the label does not show on RadGrid.
I must Comment
        //else if (e.Item is GridDataItem && !e.Item.IsInEditMode && Page.IsPostBack)
       //{
         //  GridDataItem item = e.Item
as GridDataItem;
         //  Label label = item.FindControl(
"Label1") as Label;
           
// update the label value
         // 
label.Text = Session["updatedValue"];
     //  }

Run Ok,
But SelectValue DropDownList not good. :(
I have two rows and two Droplist value. When I Select Value 1 is not always the default Select Value is the value 2 in Session.
Pls

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 May 2009, 06:30 AM
Hi Dao,

When using dropdownlist in EditItemTemplate, you can save the selected value in a Session variable and then set that value for the label in ItemTemplate. The same Session variable can be used to select the default item in the dropdown control on subsequent editing. Can you confirm that you are storing correct values in the session variable?

-Shinu.
0
Dao
Top achievements
Rank 1
answered on 22 May 2009, 07:56 AM
Hi Shinu
  view code:
<telerik:radgrid id="RadGrid1" runat="server" AutoGenerateColumns="False">
           
<MasterTableView>
              
<Columns>
                 
<telerik:GridBoundColumn UniqueName="ContactName" ReadOnly="True" HeaderText="ContactName"
                   
DataField= "ContactName" />
                 
<telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Country">
                    
<ItemTemplate>
                       
<asp:Label id="Label1" runat="server">
                          
<%# DataBinder.Eval(Container.DataItem, "Country") %>
                       
</asp:Label>
                    
</ItemTemplate>
                    
<EditItemTemplate>
                       
<asp:DropDownList id="ddl" runat="server" />
                    
</EditItemTemplate>
                 
</telerik:GridTemplateColumn>
                 
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
              
</Columns>
           
</MasterTableView>
</
telerik:radgrid>

    protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
    {
        GridEditableItem UpdateItem = e.Item as GridEditableItem;
        DropDownList list = UpdateItem.FindControl("ddl") as DropDownList;
        Session["updatedValue"] = list.SelectedValue;
        //any code here
    }

As for example in http://www.telerik.com/help/aspnet-ajax/grdoperationswithdropdownlistinedititemtemplate.html

Value is saved after clicking Update. But I want to get value and save the session when clicking the Edit button.

Help :(



0
Dao
Top achievements
Rank 1
answered on 24 May 2009, 06:18 AM
 Peoples help me. Or can show me how nearly identical to that you find elsewhere.
0
Dao
Top achievements
Rank 1
answered on 24 May 2009, 11:46 AM
I found on google but found no one do this.

As for example in http://www.telerik.com/help/aspnet-ajax/grdoperationswithdropdownlistinedititemtemplate.html
Data is compared when click on Update. It is not necessary. I do not want to follow as Telerik sqlDataSource do.

So someone help me. Shinu you say:

"When using dropdownlist in EditItemTemplate, you can save the selected value in a Session variable and then set the value for that label in ItemTemplate. The same Session variable can be used to select the default item in the dropdown control on subsequent editing. Can you confirm that you are storing the correct values in session variable? "

So please show me demo your code.

Try,try,retry hic :(
0
Shinu
Top achievements
Rank 2
answered on 25 May 2009, 11:05 AM
Hi Dao,

I guess you are not able to set the selecteditem in dropdown at the first time after clicking the Edit button. If so, you can get the value of label by using GetDataKeyValue() method and set as the dropdown selected item. Can you try following code snippet and see whether it is working fine for you?

CS:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
    { 
        GridEditFormItem item = e.Item as GridEditFormItem; 
        // access/modify the edit item template settings here 
        DropDownList list = item.FindControl("List1"as DropDownList; 
        list.DataSource = Country_values; 
        list.DataBind(); 
        if (Session["updatedValue"] != null
        { 
            list.SelectedValue = Session["updatedValue"].ToString(); 
        } 
        else 
        { 
            // Get the griddataitem and set the selected value initially 
            GridDataItem dataItem = (GridDataItem)item.ParentItem; 
            list.SelectedValue = dataItem.GetDataKeyValue("Country").ToString(); // Set the selected value initially 
        } 
    } 
    . . . 
Note: Set the DataKeyNames of Radgrid MasterTableView as "Country".

Thanks,
Shinu.
Tags
Grid
Asked by
Dao
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Dao
Top achievements
Rank 1
Share this question
or