Solved

Getting old value of the cell - Datagrid

Posted on 2004-08-10
8
1,156 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
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
 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

777 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