Hi,
I am trying to dynamically add the values entered in the cells and populate the total in another Cell. So i call total() function onTextChange in each texbox within the Grid. The entire grid postbacks, this will be annoying to the user. I need a funcationality similar to Excel where one cell holds the formula to add the values in required cells. I have pasted the code snippet here below just for testing purpose, i tried to populate one textbox with the value of other and checking the onTextChange event in each textbox within the grid.
Please let me know what needs to be fixed so that the entire page doesnot postbacks, the total value is automatically added.
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="" AutoGenerateColumns=false>
<MasterTableView DataKeyNames="WEB_ACCOUNT_ID,WEB_PER_ID,WEEK_ID,DETAIL_ID">
<Columns>
<telerik:GridTemplateColumn UniqueName="TemplateColumn">
<ItemTemplate>
<asp:TextBox ID="txt_sun_hrs" runat="server" Text='<%# Eval("SUN_HRS") %>' Width="90%"
MaxLength="4" OnTextChanged="textBox_TextChangedRad" AutoPostBack=true> </asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="TemplateColumn">
<ItemTemplate>
<asp:TextBox ID="txt_mon_prem" runat="server" Text='<%# Eval("MON_PREM") %>' Width="90%"
MaxLength="4" OnTextChanged="textBox_TextChangedRad" AutoPostBack=true></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
CodeBehind:
protected void textBox_TextChangedRad(object sender, System.EventArgs e)
{
int start, end, updatedrow;
double sun_Hrs, mon_prem;
TextBox txtHrs = ((TextBox)(sender));
GridDataItem item = (GridDataItem)txtHrs.NamingContainer;
sun_Hrs = Convert.ToDouble(((TextBox)item.FindControl("txt_sun_hrs")).Text.Equals("") ? "0" : ((TextBox)item.FindControl("txt_sun_hrs")).Text.ToString());
((TextBox)item.FindControl("txt_mon_prem")).Text = sun_Hrs.ToString();
}
I am trying to dynamically add the values entered in the cells and populate the total in another Cell. So i call total() function onTextChange in each texbox within the Grid. The entire grid postbacks, this will be annoying to the user. I need a funcationality similar to Excel where one cell holds the formula to add the values in required cells. I have pasted the code snippet here below just for testing purpose, i tried to populate one textbox with the value of other and checking the onTextChange event in each textbox within the grid.
Please let me know what needs to be fixed so that the entire page doesnot postbacks, the total value is automatically added.
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="" AutoGenerateColumns=false>
<MasterTableView DataKeyNames="WEB_ACCOUNT_ID,WEB_PER_ID,WEEK_ID,DETAIL_ID">
<Columns>
<telerik:GridTemplateColumn UniqueName="TemplateColumn">
<ItemTemplate>
<asp:TextBox ID="txt_sun_hrs" runat="server" Text='<%# Eval("SUN_HRS") %>' Width="90%"
MaxLength="4" OnTextChanged="textBox_TextChangedRad" AutoPostBack=true> </asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="TemplateColumn">
<ItemTemplate>
<asp:TextBox ID="txt_mon_prem" runat="server" Text='<%# Eval("MON_PREM") %>' Width="90%"
MaxLength="4" OnTextChanged="textBox_TextChangedRad" AutoPostBack=true></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
CodeBehind:
protected void textBox_TextChangedRad(object sender, System.EventArgs e)
{
int start, end, updatedrow;
double sun_Hrs, mon_prem;
TextBox txtHrs = ((TextBox)(sender));
GridDataItem item = (GridDataItem)txtHrs.NamingContainer;
sun_Hrs = Convert.ToDouble(((TextBox)item.FindControl("txt_sun_hrs")).Text.Equals("") ? "0" : ((TextBox)item.FindControl("txt_sun_hrs")).Text.ToString());
((TextBox)item.FindControl("txt_mon_prem")).Text = sun_Hrs.ToString();
}