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

How to retrieve text box value set from clientside at server postback in radgrid?

1 Answer 608 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Harshit
Top achievements
Rank 1
Harshit asked on 30 Sep 2011, 01:57 AM
I have standard asp textbox as template column in radgrid and I change value of that text box through client side. This textbox is disabled but I can see value getting updated in textbox on grid. When I  click save and loop through data items of grid, value for that textbox is empty.

 <Columns>     
               <telerik:GridTemplateColumn HeaderText="Amount" UniqueName="Amount">                     <ItemTemplate>                         <asp:textbox ID="txtamount" runat="server" enabled="false" >  </asp:textbox>                     </ItemTemplate>                 </telerik:GridTemplateColumn>             </Columns>
Is there any other alternative to this? I need to save this value for each row in grid.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Sep 2011, 09:17 AM
Hi Harshit,

You faced the problem because the textbox is disabled. So one suggestion is just set the value of TextBox in a HiddenField and access the HiddenField value at server postback. Here is the code.

JavaScript:
<script type="text/javascript" language="javascript">
    function test(id)
{
    var grid = $find(id);
    var tableView = grid.get_masterTableView();
    var items = tableView.get_dataItems();
    for (var i = 0; i < items.length; i++)
    {
      var rowValues = items[i];
      var Textvalue = rowValues.findElement("TextBox1");
      var Hiddentext = rowValues.findElement("HiddenField1");
      Textvalue.value = "dfsd";
      Hiddentext .value = Textvalue.value;
           
    
}
</script>

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       Button1.Attributes.Add("onclick", "test('" + RadGrid1.ClientID + "');return false");
   }
   protected void Button2_Click(object sender, EventArgs e)
   {
       foreach (GridDataItem item1 in RadGrid1.Items)
       {
           GridDataItem item = (GridDataItem)item1;
           HiddenField hidden1= (HiddenField)item.FindControl("HiddenField1");
           string hiddentext= hidden1.Value;
        }
   }

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