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

Problem with binding data grid on Text Changed Event

4 Answers 399 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Durga
Top achievements
Rank 1
Durga asked on 25 Feb 2013, 01:22 PM
Hi,

I am rebinding data grind on text changed event. When I changed the text in the text box, the data in the data grid need to reload. If I change the text in the text box which is in first row, the grid is reloading but the text box is missing on first row. But I am not getting issues when I changed the text in other rows.

I tried both data grid and rad grid.

I am using the below code,

.aspx Page Code

<rad:RadCodeBlock ID="RadCodeBlock1" runat="server">
 

<asp:datagrid id="Datagrid1" runat="server" Width="100%" AutoGenerateColumns="False" BorderColor="#B6B9BE" BorderWidth="1px" BorderStyle="Solid">
--Bound columns--
<asp:TemplateColumn
<ItemTemplate>

 <asp:TextBox ID="txt_QPercent" runat="server" Width="100%" Text='<%#Container.DataItem("RevisedPercent")%>' onkeydown="return jsDecimals(event,this.value);" MaxLength="3" onchange="SavePercent(this);" OnTextChanged="ReLoadGrid" AutoPostBack="True"></asp:TextBox>

</asp:TemplateColumn> 

</ItemTemplate>

 

</asp:datagrid>


</rad:RadCodeBlock>

<rad:RadAjaxManager ID="RadAjaxManager1" runat="server">

 

<AjaxSettings>

 

<rad:AjaxSetting AjaxControlID="txt_QPercent"> 
<UpdatedControls

<rad:AjaxUpdatedControl ControlID="txt_QPercent" />

<rad:AjaxUpdatedControl ControlID="DgQAccounts" />

 
</UpdatedControls>

 

 </AjaxSettings>

 

</rad:RadAjaxManager>

 


Code Behind - aspx.vb

Public

 

Sub ReLoadGrid(ByVal sender As Object, ByVal e As System.EventArgs)

 

BindGrid(ID)--Binding the data in the function

 

End Sub

 


Thanks,
Durga Rao

4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 28 Feb 2013, 11:30 AM
Hi Durga,

Can you please elaborate on your specific scenario? Do you use the Rebind or DataBind method?
Please note that performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, grouping, Paging, Sorting, Filtering require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding

Additionally, if you want to modify the grid structure dynamically, please check out the following topic:
http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Durga
Top achievements
Rank 1
answered on 28 Feb 2013, 01:19 PM
Hi Eyup,

I used databind() method to rebind the data. I didn't used any of the operations line insert, delete, edit, sorting and filtering. I am copying the complete code for your reference
--Data Grid

<rad:RadCodeBlock ID="RadCodeBlock1" runat="server">

 

 

<asp:datagrid id="DgQAccounts" runat="server" Width="100%" AutoGenerateColumns="False" BorderColor="#B6B9BE" BorderWidth="1px" BorderStyle="Solid">

 

 

<HeaderStyle Font-Bold="True" CssClass="DBX.css" BackColor="#EBEBE1"></HeaderStyle>

 

 

<Columns>

 

 

<asp:BoundColumn DataField="ActivityCenterNumber" HeaderText="Activity Center #" ItemStyle-CssClass="TableBody8" HeaderStyle-Wrap="false" />

 

 

<asp:BoundColumn DataField="ActivityCenterName" HeaderText="Activity Center Description" ItemStyle-CssClass="TableBody8" HeaderStyle-Wrap="false" />

 

 

<asp:BoundColumn DataField="AccountNumber" HeaderText="Account #" ItemStyle-CssClass="TableBody8" HeaderStyle-Wrap="false" />

 

 

<asp:BoundColumn DataField="AccountName" HeaderText="Account Name" ItemStyle-CssClass="TableBody8" HeaderStyle-Wrap="false" />

 

 

<asp:BoundColumn DataField="AccountType" HeaderText="Account Type" ItemStyle-CssClass="TableBody8" HeaderStyle-Wrap="false" />

 

 

<asp:BoundColumn DataField="Amount" HeaderText="Original Amount" ItemStyle-CssClass="TableBody8" HeaderStyle-Wrap="false" DataFormatString="{0:C0}" />

 

 

<asp:BoundColumn DataField="CacAmount" HeaderText="Final Amount" ItemStyle-CssClass="TableBody8" HeaderStyle-Wrap="false" DataFormatString="{0:C0}"/>

 

 

<asp:TemplateColumn HeaderText="Is this RD Account?" ItemStyle-CssClass="TableBody8" HeaderStyle-Wrap="True" ItemStyle-HorizontalAlign="center">

 

 

<ItemTemplate>

 

 

<asp:Panel ID="Panel1" runat="server"><asp:RadioButton ID="rbtn_RnDCostYes" runat="server" GroupName="RBTNRnDCostYesNo" onclick="ValidateRDCheckbox(this)" Text="Yes" Checked='<%#Container.DataItem("IsRDCostYes")%>' />&nbsp;<asp:RadioButton ID="rbtn_RnDCostNo" onclick="ValidateRDCheckbox(this)" runat="server" GroupName="RBTNRnDCostYesNo" Text="No" Checked='<%#Container.DataItem("IsRDCostNo")%>' OnCheckedChanged="ReLoadGrid" AutoPostBack="True" /></asp:Panel>

 

 

</ItemTemplate>

 

 

</asp:TemplateColumn>

 

 

<asp:TemplateColumn HeaderText="PC Revised Q%" ItemStyle-CssClass="TableBody8" HeaderStyle-Wrap="True">

 

 

<ItemTemplate>

 

 

<asp:TextBox ID="txt_QPercent" runat="server" Width="100%" Text='<%#Container.DataItem("PCRevisedPercent")%>' onkeydown="return jsDecimals(event,this.value);" MaxLength="3" onchange="SavePercent(this);" OnTextChanged="ReLoadGrid" AutoPostBack="True"></asp:TextBox>

 

 

</ItemTemplate>

 

 

</asp:TemplateColumn>

 

 

<asp:TemplateColumn HeaderText="Final Amount Reviewed" ItemStyle-CssClass="TableBody8" HeaderStyle-Wrap="True" ItemStyle-HorizontalAlign="center">

 

 

<ItemTemplate>

 

 

<asp:label id="lbl_expclassid" runat="server" Text='<%#Container.DataItem("AccountID")%>' CssClass="DoNotShow"></asp:label>

 

 

<asp:label id="lbl_QNQLevel1ID" runat="server" Text='<%#Container.DataItem("ActivityCenterID")%>' CssClass="DoNotShow"></asp:label>

 

 

<asp:RadioButton ID="rbtn_IsAmountReviewedYes" runat="server" GroupName="RBTNIsAmountReviewedYesNo" Text="Yes" Checked='<%#Container.DataItem("IsAmountReviewedYes")%>' onclick="ValidateIsAmountReviewedCheckbox(this)" />&nbsp;<asp:RadioButton ID="rbtn_IsAmountReviewedNo" runat="server" GroupName="RBTNIsAmountReviewedYesNo" Text="No" Checked='<%#Container.DataItem("IsAmountReviewedNo")%>' onclick="ValidateIsAmountReviewedCheckbox(this)" />

 

 

</ItemTemplate>

 

 

</asp:TemplateColumn>

 

 

</Columns>

 

 

</asp:datagrid>

 

 

</rad:RadCodeBlock>

--Teleric Calling

 

<rad:RadAjaxManager ID="RadAjaxManager1" runat="server">

 

 

 

 

 

<AjaxSettings>

 

 

 

 

 

<rad:AjaxSetting AjaxControlID="txt_QPercent">

 

 

 

 

 

<UpdatedControls>

 

 

 

 

 

<rad:AjaxUpdatedControl ControlID="txt_QPercent" />

 

 

 

 

 

<rad:AjaxUpdatedControl ControlID="DgQAccounts" />

 

 

 

 

 

</UpdatedControls>

 

 

 

 

 

</rad:AjaxSetting>

 

 

 

 

 

<rad:AjaxSetting AjaxControlID="Panel1">

 

 

 

 

 

<UpdatedControls>

 

 

 

 

 

<rad:AjaxUpdatedControl ControlID="Panel1" />

 

 

 

 

 

<rad:AjaxUpdatedControl ControlID="DgQAccounts" />

 

 

 

 

 

</UpdatedControls>

 

 

 

 

 

</rad:AjaxSetting>

 

 

 

 

 

</AjaxSettings>

 

 

 

 

 

</rad:RadAjaxManager>

--Code Behind

 

Public

 

Sub ReLoadGrid(ByVal sender As Object, ByVal e As System.EventArgs)

 

Dim dt As DataTable= Obj.GetQualifiedSnK(InterviewID,

"K", "tblcontracts")

 

 

If dt .Rows.Count = 0 Then

 

DgQAccounts.Visible =

False

 

 

Else

 

DgQAccounts.DataSource = dt 

DgQAccounts.DataBind()

 

End If

 

 

End Sub

--Comments

From the above code the error giving control is

 

<asp:TextBox ID="txt_QPercent" runat="server" Width="100%" Text='<%#Container.DataItem("PCRevisedPercent")%>' onkeydown="return jsDecimals(event,this.value);" MaxLength="3" onchange="SavePercent(this);" OnTextChanged="ReLoadGrid" AutoPostBack="True"></asp:TextBox>

 


onkeydown="return jsDecimals(event,this.value);"  -  function, I am validating it to allow only numbers
onchange="SavePercent(this);"  function I am saving the percent to the database using Ajax.
OnTextChanged="ReLoadGrid" - function will rebind the data to the grid again after saving the percentage.

When I changed the text on any row except first row, the grid is reloding properly. If I changed the text on first row, the data is saving to the database and the grid is reloading, but the text box on the first row is missing.

Thanks,
Durga
0
Eyup
Telerik team
answered on 05 Mar 2013, 01:03 PM
Hi Durga,

You will need to modify the ajax settings of the manager. It is sufficient the grid to update itself:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="DgQAccounts">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="DgQAccounts" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

It works as expected on my end. Please give it a try and let me know about the result.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Durga
Top achievements
Rank 1
answered on 07 Mar 2013, 09:09 AM
Thank You Eyup

It is working perfectly in my system too.
Tags
Ajax
Asked by
Durga
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Durga
Top achievements
Rank 1
Share this question
or