Solved

Retrieve ASP .Net Datagrid ButtonColumn Text

Posted on 2004-10-08
7
475 Views
Last Modified: 2010-08-05
I have created a datagrid with a buttoncolumn and a few boundcolumn.
When I click the buttoncolumn, the values of the row should be retrieved and fill up some textboxes. However, the value of the buttoncolumn is blank, which should be the value retrieved from the database and displayed in the datagrid. Any idea on this? Thanx
0
Comment
Question by:scissorhand
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:Gregsy
ID: 12257140
Is this on Page_load or on Postback

if it on postback are you populating what you need to in the event?

Cheers
Alan
0
 

Author Comment

by:scissorhand
ID: 12257231
i populate the data in the datagrid when the page is first loaded. The data will be repopulated when i click the retrieve button. now i can get every value of the bound column except the button column
0
 
LVL 1

Accepted Solution

by:
Gregsy earned 50 total points
ID: 12257251
Does it work if you convert that column to a template column?

0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 6

Assisted Solution

by:margant
margant earned 30 total points
ID: 12259015
Can you show the code?
Are you sure the database hit returns something?
Do you have an button action function OnItemCommand defined in the datagrid? And more importangly - do u rebind your data in that function after you are finished? (last one got me debuggin for some time in the past)


Hope that helps,
-AM
0
 

Author Comment

by:scissorhand
ID: 12274157
i do put OnItemCommand and all the columns value are returned except the buttoncolumn, the code is roughly like this

DgCounter.SelectedIndex = e.Item.ItemIndex ' DgCounter is a datagrid
TbCounterKey.Text = e.Item.Cells(1).Text ' TbCounterKey is a textfield
TbCounterNum.Text = e.Item.Cells(2).Text

I put the code in the itemcommand function
0
 
LVL 6

Expert Comment

by:margant
ID: 12276877
Hm, since I cant see the rest of the code, did you get a chance to review this great article on how to work buttons in Datagrid?

http://aspnet.4guysfromrolla.com/articles/042402-1.aspx
(esp part 2)

I have one more idea of why code may fail :
where do u load ur datagrid? page_load?
make sure its loaded like this, VERY important, otherwise ur e.Item.ItemIndex is reset on every postback
if not ispostback then
  'datagrid databind here
end if

Best of luck,
AM
0
 

Author Comment

by:scissorhand
ID: 12283490
I load the datagrid when I click a retrieve button. But I have tested and find that e.Item.ItemIndex is correct as I can retrieve the value of other columns in the same row. By the way I use template column and put in link button to replace the bound column. It works fine now, thanx to u all.

Margant, if u figure out what happen to the button column, I am interested to know it, thanx.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

840 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