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

Using javascript to check hidden fields in grid

5 Answers 453 Views
Grid
This is a migrated thread and some comments may be shown as answers.
aks
Top achievements
Rank 1
aks asked on 27 May 2008, 02:19 PM
How do I access the hidden field in my grid using JavaScript?  I need to loop thru my grid and check the values the hidden field in all rows when the user hits the submit button.  Values of the hidden field will be YES or NO.  Can someone show me the JavaScript function?
Thanks!
 
   <rad:RadGrid ID="StatesGrid" OnNeedDataSource="StatesGrid_NeedDataSource" AllowMultiRowSelection="true"
      ClientSettings-Scrolling-AllowScroll="true" Skin="Outlook2007" runat="server" AllowSorting="True"
      GridLines="None" AutoGenerateColumns="False" Height="250px" TabIndex="4">
      <MasterTableView>
        <RowIndicatorColumn Visible="False">
          <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn Visible="False" Resizable="False">
          <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <Columns>
          <rad:GridClientSelectColumn UniqueName="GridClientSelectColumn" />
          <rad:GridTemplateColumn HeaderText="All States" UniqueName="TemplateColumnTotalAmount">
            <ItemTemplate>
              <asp:Label ID="Label1" Text='<%# DisplayStateNames(Container) %>' runat="server"></asp:Label>
              <asp:HiddenField ID="hdnIndicator" Value='<%# Eval("Ind_Active") %>' runat="server" />
            </ItemTemplate>
          </rad:GridTemplateColumn>
        </Columns>
      </MasterTableView>
      <ClientSettings ApplyStylesOnClient="True">
        <Selecting AllowRowSelect="True"></Selecting>
        <Scrolling AllowScroll="True"></Scrolling>
      </ClientSettings>
    </rad:RadGrid>

5 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 28 May 2008, 07:45 AM
Hi aks,

To see more information on how to get the cell value, please refer to the following article.
I hope this information helps.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
aks
Top achievements
Rank 1
answered on 28 May 2008, 03:51 PM
I am able to access the actual column with your suggestion, however, that is returning a bunch of html using innerHTML.  I want the SINGLE value of the hidden field returned to a variable.

JS:
function buildList()
{
for (var ix = 0; ix < LendersGrid.MasterTableView.SelectedRows.length; ix++)
{
var row = LendersGrid.MasterTableView.SelectedRows[ix];
var CategoryID = LendersGrid.MasterTableView.GetCellByColumnUniqueName(row ,"TemplateColumnTotalAmount2");
alert(CategoryID.innerHTML);
}
}


ASPX:
<rad:GridTemplateColumn HeaderText="All Lenders" UniqueName="TemplateColumnTotalAmount2">
<ItemTemplate>
<asp:Label ID="Label2" Text='<%# DisplayLenderNames(Container) %>' runat="server"></asp:Label>
<asp:HiddenField ID="hdnLenderNumber" Value='<%# Eval("LenderNumber") %>' runat="server" />
<asp:HiddenField ID="hdnOrgNumber" Value='<%# Eval("OrganizationNumber") %>' runat="server" />
<asp:HiddenField ID="HiddenField1" Value='<%# Eval("SharedLogo") %>' runat="server" />
</ItemTemplate>
</rad:GridTemplateColumn>
0
Yavor
Telerik team
answered on 02 Jun 2008, 10:29 AM
Hi aks,

Indeed, the innerHTML will return the HTML representation in a more complex scenario when you have nested hidden inputs along with a lable. This will be something like:

"<ITEMTEMPLATE><SPAN id=RadGrid1_ctl00_ctl04_Label2>ALFKI</SPAN> <INPUT id=RadGrid1_ctl00_ctl04_hdnLenderNumber type=hidden value="Around the Horn < >OffShore" name=RadGrid1$ctl00$ctl04$hdnLenderNumber> <INPUT id=RadGrid1_ctl00_ctl04_hdnOrgNumber type=hidden name=RadGrid1$ctl00$ctl04$hdnOrgNumber> <INPUT id=RadGrid1_ctl00_ctl04_HiddenField1 type=hidden value=1234- name=RadGrid1$ctl00$ctl04$HiddenField1> </ITEMTEMPLATE>"

In this case, you can get the cell (as opposed to the .innerHTML property), and use the childNodes property to get to one of the nested items, and then access its properties.

Sincerely yours,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
aks
Top achievements
Rank 1
answered on 02 Jun 2008, 02:43 PM
Can you please post the JavaScript to do this?  Can you show how to put this in an XML variable and then acces the child node?  I am not familair.

Thank you so much.
0
Yavor
Telerik team
answered on 04 Jun 2008, 11:03 AM
Hello aks,

Actually, the Js code is pretty similar to the  one posted earlier:

.Js
var CategoryID = LendersGrid.MasterTableView.GetCellByColumnUniqueName(row ,"TemplateColumnTotalAmount2");

Thus, the CategoryID cell will have childNodes, which will contain all the nested items in the template column.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
aks
Top achievements
Rank 1
Answers by
Yavor
Telerik team
aks
Top achievements
Rank 1
Share this question
or