By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Update textbox in datagrid

P: n/a
Hey folks
I am having a weird problem in ASP .Net. My page is in C#. I have a
datagrid, which populates based on selection in drop down box on ASP
page. This datagrid has template textbox colum in itemtemplate.
Datagrid is something like this-

Category Week Amt Week% Button
Revenue 1 100 Update
Revenue 2 200 Update
Cost 1 25 25
Cost 2 40 20

Now I have procedure in itemcommand event of datagrid, which detects
if update button is pressed and this means that Cost number is
re-calculated based on corresponding week%. Therefore if user changes
Revenue for week 1 to 200, then Cost is recalculated for week 1 as 50.
When i click Update button, everything works, fine, page is re-posted
and cost is re-calculated as 50.
Although my user wants to update this number without having to click
button. He wants Cost number to be updated as soon as he hits enter on
textbox after changing revenue number.
I tried raising OnTextChange event on txtbox and writing same piece of
code I used on ItemCommand for button but when I hit enter after
changing number, page re-posts and it doesnt retain any changes i made
to revenue and subsequently in Cost value. Next I tried debugging by
printing number for Cost on a label text value. It did actually gave
me new value for Cost but when it re-populated grid, all changes were
gone. What could be wrong?
I also understand that I can run this calculation on client side
rather than going back to server, which is unnecessary, as I just need
to re-calculate Cost based on changed Revenue and Week%. For client
side, i can write some kind of javascript to make this update.
Am I thinking correct by trying to do something on client side using
javascript? If then any sample code to achieve this in javascript will
be appreciated. Alternatively, if it makes sense to do on server side,
than what could be wrong in my OnTextChange event?

Thanks in advance
Manish
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi manish,
You can bind the java script on the itembound event.
(You must bind the data again and again to the datagrid in
postback and after postback)

Textbox1 txtBox = e.FindControl("TextBoxName);
txtBox.Attributes.ADD("onblur", "JAVASCript to be added")

Regards,
Srini
-----Original Message-----
Hey folks
I am having a weird problem in ASP .Net. My page is in C#. I have adatagrid, which populates based on selection in drop down box on ASPpage. This datagrid has template textbox colum in itemtemplate.Datagrid is something like this-

Category Week Amt Week% Button
Revenue 1 100 Update
Revenue 2 200 Update
Cost 1 25 25
Cost 2 40 20

Now I have procedure in itemcommand event of datagrid, which detectsif update button is pressed and this means that Cost number isre-calculated based on corresponding week%. Therefore if user changesRevenue for week 1 to 200, then Cost is recalculated for week 1 as 50.When i click Update button, everything works, fine, page is re-postedand cost is re-calculated as 50.
Although my user wants to update this number without having to clickbutton. He wants Cost number to be updated as soon as he hits enter ontextbox after changing revenue number.
I tried raising OnTextChange event on txtbox and writing same piece ofcode I used on ItemCommand for button but when I hit enter afterchanging number, page re-posts and it doesnt retain any changes i madeto revenue and subsequently in Cost value. Next I tried debugging byprinting number for Cost on a label text value. It did actually gaveme new value for Cost but when it re-populated grid, all changes weregone. What could be wrong?
I also understand that I can run this calculation on client siderather than going back to server, which is unnecessary, as I just needto re-calculate Cost based on changed Revenue and Week%. For clientside, i can write some kind of javascript to make this update.Am I thinking correct by trying to do something on client side usingjavascript? If then any sample code to achieve this in javascript willbe appreciated. Alternatively, if it makes sense to do on server side,than what could be wrong in my OnTextChange event?

Thanks in advance
Manish
.

Nov 17 '05 #2

P: n/a
Srini
I have little experience in javascript. How can I access datagrid
cells in javascript? I guess this javascript has to be embedded on
HTML design section rather than C# class.
Any example of similar javascript using datagrid will be appreciated.

Thanks again
Manish
"Srini" <an*******@discussions.microsoft.com> wrote in message news:<07****************************@phx.gbl>...
Hi manish,
You can bind the java script on the itembound event.
(You must bind the data again and again to the datagrid in
postback and after postback)

Textbox1 txtBox = e.FindControl("TextBoxName);
txtBox.Attributes.ADD("onblur", "JAVASCript to be added")

Regards,
Srini
-----Original Message-----
Hey folks
I am having a weird problem in ASP .Net. My page is in

C#. I have a
datagrid, which populates based on selection in drop down

box on ASP
page. This datagrid has template textbox colum in

itemtemplate.
Datagrid is something like this-

Category Week Amt Week% Button
Revenue 1 100 Update
Revenue 2 200 Update
Cost 1 25 25
Cost 2 40 20

Now I have procedure in itemcommand event of datagrid,

which detects
if update button is pressed and this means that Cost

number is
re-calculated based on corresponding week%. Therefore if

user changes
Revenue for week 1 to 200, then Cost is recalculated for

week 1 as 50.
When i click Update button, everything works, fine, page

is re-posted
and cost is re-calculated as 50.
Although my user wants to update this number without

having to click
button. He wants Cost number to be updated as soon as he

hits enter on
textbox after changing revenue number.
I tried raising OnTextChange event on txtbox and writing

same piece of
code I used on ItemCommand for button but when I hit

enter after
changing number, page re-posts and it doesnt retain any

changes i made
to revenue and subsequently in Cost value. Next I tried

debugging by
printing number for Cost on a label text value. It did

actually gave
me new value for Cost but when it re-populated grid, all

changes were
gone. What could be wrong?
I also understand that I can run this calculation on

client side
rather than going back to server, which is unnecessary,

as I just need
to re-calculate Cost based on changed Revenue and Week%.

For client
side, i can write some kind of javascript to make this

update.
Am I thinking correct by trying to do something on client

side using
javascript? If then any sample code to achieve this in

javascript will
be appreciated. Alternatively, if it makes sense to do on

server side,
than what could be wrong in my OnTextChange event?

Thanks in advance
Manish
.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.