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

RadGrid in EditMode lost data after DropDown postback

2 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allin
Top achievements
Rank 1
Allin asked on 23 Sep 2013, 02:47 PM
Hi,

I have a field in the RadMaskedTextBox RadGrid in edit mode and I have a Handler on TextChanged this field to set a default value in another field in the input value. By the postback, I lose the information contained in my other fields that are not updated by the action of the TextChanged. What is the best strategy to solve this problem and keep data into field1 and field2?

Field1 (textbox), Field2 (textbox), Field3 (textchanged), Field4 (set default value by field3 textchanged from server-side)

Thank you.


2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 24 Sep 2013, 08:54 AM
Hi Allin,

I guess you want to change the value of  a textbox to the value entered in another textbox during editmode.Please try the following code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
    GridLines="None" AllowPaging="true" AutoGenerateEditColumn="true">
    <MasterTableView DataKeyNames="OrderID">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
            <telerik:GridTemplateColumn HeaderText="ShipPostalCode">
                <ItemTemplate>
                    <%# Eval("ShipPostalCode")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadMaskedTextBox ID="RadMaskedTextBox2" runat="server" Mask="(###) ###-####"
                        Text='<%# Bind("ShipPostalCode") %>' Width="125px" OnTextChanged="TextBox1_TextChanged"
                        AutoPostBack="true">
                    </telerik:RadMaskedTextBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="ShipVia" HeaderText="ShipVia" UniqueName="ShipVia" />
            <telerik:GridTemplateColumn HeaderText="EmployeeID">
                <ItemTemplate>
                    <%# Eval("EmployeeID")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" DataTextField="EmployeeID" DataSourceID="SqlDataSource1"
                        DataValueField="EmployeeID" AutoPostBack="true">
                    </asp:DropDownList>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void TextBox1_TextChanged(object sender, EventArgs e)
 {   
    RadMaskedTextBox txt = sender as RadMaskedTextBox;
    GridEditableItem edit = (GridEditableItem)txt.NamingContainer;
    string value = txt.Text;
    TextBox txt2 = (TextBox)edit["ShipVia"].Controls[0];
    txt2.Text = value;
 }

Thanks,
Shinu
0
Allin
Top achievements
Rank 1
answered on 30 Sep 2013, 05:02 PM
I solved the problem. I created my columns dynamically instead of putting them in the markup.

ty
Tags
Grid
Asked by
Allin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Allin
Top achievements
Rank 1
Share this question
or