Solved

Getting old value of the cell - Datagrid

Posted on 2004-08-10
8
1,154 Views
Last Modified: 2008-02-26
Hi Experts,

I've a datagrid in a webform in which I have 2 columns, both defined as templatecolumns. First column is a textbox and second is a dropdownlist. E'thing is fine so far. What I need is this.

When I try to edit this, I need to fetch the current value of both the cells before I edit. How to do this? It works fine if I use a bound column and use this..

e.Item.Cells[1].Text;

But this I reckon won't work with a templatecolumn. How will I fetch the value of the cells? I hope I'm clear with the problem.

TIA & cheers,
kaykay!
0
Comment
Question by:skaykay
  • 4
  • 4
8 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 11761664
Hi,

to get contents of the cell when you use Template column you have to use this

TextBox _tb = (TextBox)e.Item.FindControl("id of the textbox control");
then _tb.Text will return the contents of the text box


for the dropdownlist it is absoulutely the same:

DropDownList _drp = (DropDownList)e.Item.FindControl(" id of the dropdownlist control");


Regards,
B..M
0
 
LVL 4

Author Comment

by:skaykay
ID: 11761698
Thanks for your response.

This findControl(<ctrlname>) gets the current value of the cell after I make any changes. What if I need the value of the cell before I make the changes. I need these values too to write my update command.

hope I'm clear.
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 11761749
i show you the way
the value that this code will get depends on the place you execute it
so, in your case you have to get this value before bind the datagrid, because after that you'll be able to change it

so in my opinion the best way to get values is to keep the dataset in a session object so you will have all the values
then when submit the page you will have the new one and you can easy compare them

B..M
0
 
LVL 4

Author Comment

by:skaykay
ID: 11761835
I get your point, but is this the solution? I'm currently struck at Edit and Delete function of a  datagrid. I choose to edit and then change the value of the columns. Now at edit, I can't update the record coz I don't have the previous value of the column.

Now where do you suggest me to populate the dataset and how do I check the old and new record correspondingly?

kaykay!
0
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.

 
LVL 28

Accepted Solution

by:
mmarinov earned 150 total points
ID: 11761921
ok, here is the way

Page_load
 if not ispostback then
    call BindGrid sub
 end if

BindGrid
    if Session("DataSourceOld") Nothing
    get dataset(or datatable or the object that will be set the datasource property of datagrid to )
    add this object to a session object named DataSourceOld
    End If
    bind grid

DataGrid edit command
  set the edit item
  call BindGrid sub

DataGrid save commnad
  from session collection with key DataSourceOld get the old data
  get the new data
  compare them
  update date
  call BindGrid sub


Hope this helps
Regards
B..M
0
 
LVL 4

Author Comment

by:skaykay
ID: 11762643
Thanks BM.. I was pondering over the point that you said and something else struck me... I did a workaround to this by adding corresponding non visible readonly columns to which I need the old value. And then use this in my function.

Not sure if this is efficient one, but solves my purpose. Do you have any comments on this workaround?
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 11762820
yes, this is also a solution and it is not a problem to use it
actually a prefer to use the solution with the session because i have to keep the data in the memory because i don't want to call every time to the database
unfortunatelly this solution is not applicable in every case becase in most of the cases the information is updated many times and you have to show to the client the newest one

so if this workaround work for you - it is great
may one day when you have time you can check the other solution and compare them

Regards
B..M
0
 
LVL 4

Author Comment

by:skaykay
ID: 11762874
yep, I should certainly do that a day. Thanks a lot for your time and response.

Cheers & have fun!
kaykay!
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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

910 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

20 Experts available now in Live!

Get 1:1 Help Now