?
Solved

Getting old value of the cell - Datagrid

Posted on 2004-08-10
8
Medium Priority
?
1,171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

766 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