• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 975
  • Last Modified:

update hidden field in gridview using javascript

I have a gridview which contains a hidden field and a check box. Some of the check boxes will be populated and some not.

Without postback the user will make some changes and click update. when it updates i only want to change the ones that have changed so i have added a hidden field and what i want to do is set the hidden field value to 1 only on those rows where a change is made. I'm thinking this can be done using js but i dont know how?
0
LBGUC04
Asked:
LBGUC04
1 Solution
 
Tyler LaczkoCommented:
document.getElementById("itemID").value  to get your value

document.getElementById("itemID").value = "1";
0
 
P1ST0LPETECommented:
You are right, that you can use JavaScript to do this, and professionalc is also right in how to set the value of a hidden field.  However, I think what you're looking for is a little bit more complicated than what his answer covers.  Can you provide the code for your gridview control, so we can see your actual grid make up and provide you with a better answer?
0
 
jagssiduralaCommented:
For example you have one text box and check box


.aspx
------------

<asp:gridview ......

<Columns>
<TemplateField>
<ItemTemplate>
<asp:checkBox onclick="fnUpdateHiddenvalue(this.tag)" tag="hdnUpdate" ...............</asp:checkBox>
<asp:Hiddenfield Id="hdnUpdate" .........../>
</ItemTemplate>
</TemplateField>

<TemplateField>
<ItemTemplate>
<asp:TextBox onblur="fnUpdateHiddenvalue(this.tag)" tag="hdnUpdate" ...............</asp:checkBox>
</ItemTemplate>
</TemplateField>

</Columns>

</asp:Gridview>


Js function
----------------

function fnUpdateHiddenvalue(hdnId)
{
document.getElementById(hdnId).value = "1";
}


Note: tag="hdnUpdate" , Where hdnUpdate is hidden field id, this code may varies if you use any master pages as hiddenfield rendered diffrently like ctl00_Contentplaceholder1_00_hdnUpdate.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now