Solved

update hidden field in gridview using javascript

Posted on 2010-11-10
3
958 Views
Last Modified: 2012-05-10
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
Comment
Question by:LBGUC04
3 Comments
 
LVL 10

Expert Comment

by:Tyler Laczko
ID: 34105458
document.getElementById("itemID").value  to get your value

document.getElementById("itemID").value = "1";
0
 
LVL 10

Expert Comment

by:P1ST0LPETE
ID: 34105980
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
 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 total points
ID: 34108570
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now