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

[Solved] Update the editable fields in the column

1 Answer 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Telerikuser
Top achievements
Rank 1
Telerikuser asked on 04 Jun 2009, 12:45 AM

I have a GripTemplateColumn which I dynamically (onItemDatabound) creating Checkbox, ComboBox, TextBox depending on the type of the data. I want to do update by having an update link/button next to the control column and do update. Can someone give me suggestion to implement it?

Here is the .aspx code I am using

<telerik:GridTemplateColumn HeaderText="Value" HeaderStyle-Width="40%">
                    <ItemTemplate>                  
                    <telerik:RadTextBox ID="txtBoxValue" runat="server" Visible="false"></telerik:RadTextBox>
                    <telerik:RadNumericTextBox ID="numericTxtBoxValue" runat="server" Visible="false"></telerik:RadNumericTextBox>
                    <telerik:RadComboBox ID="dropDownValue" runat="server" Visible="false">
                        <Items>       <telerik:RadComboBoxItem id="Item1" runat="server"></telerik:RadComboBoxItem>
      </Items>
                    </telerik:RadComboBox>
                    <asp:CheckBox ID="chkBox" runat="server" Visible="false"></asp:CheckBox>                   
                    </ItemTemplate>

Here is the code how I populate the checkbox and other controls in the Grid ItemDataBound

CheckBox chkBoxValue = e.Item.FindControl("chkBox") as CheckBox;
                        chkBoxValue.ID = "chkValue";
                        if (value == "1" || value == "True")
                            chkBoxValue.Checked = true;
                        else
                            chkBoxValue.Checked = false;
                        chkBoxValue.Visible = true;

Here is the code for Update Link columm :

                    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Update" Text="Update"
                        UniqueName="UpdateColumn">
                        <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                    </telerik:GridButtonColumn>

But I could not get the updated value of the controls inside the UpdateCommand method of the code behind.

I checked the onle demo and help but all of them are using the inline edit or some sort of built in edit mode to edit all the columns of the row. In my case I just need to update only one column and it is already displayed in a editable form i.e in textbox, combobox etc. I just need to click the Update button for each row and save the edited value.

Any suggestion is appreciated!
 

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 09 Jun 2009, 07:26 AM
Hi Subi,

The problem seems to come from the binding approach used to bind RadGrid to its data source. Are you rebinding your grid on every postback? Please try specifying the data source of RadGrid in it's NeedDataSource event as described in this help article from the online documentation.

I have tested a sample project on this principle, where a GridTemplateColumn contains several controls in its ItemTemplate, and a Update button calling RadGrid's UpdateCommand. The values are preserved as expected.

You can see how this approach relates to your project.

Sincerely yours,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Telerikuser
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or