Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 510
  • Last Modified:

Retrieve ASP .Net Datagrid ButtonColumn Text

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
scissorhand
Asked:
scissorhand
  • 3
  • 2
  • 2
2 Solutions
 
GregsyCommented:
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
 
scissorhandAuthor Commented:
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
 
GregsyCommented:
Does it work if you convert that column to a template column?

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
margantCommented:
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
 
scissorhandAuthor Commented:
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
 
margantCommented:
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
 
scissorhandAuthor Commented:
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

Independent Software Vendors: 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!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now