Solved

Retrieve ASP .Net Datagrid ButtonColumn Text

Posted on 2004-10-08
7
461 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 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

8 Experts available now in Live!

Get 1:1 Help Now