Solved

update hidden field in gridview using javascript

Posted on 2010-11-10
3
961 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

26 Experts available now in Live!

Get 1:1 Help Now