Common problem - please help explain this one

G

Guest

Subject: Re: ButtonColumn postback problem 3/9/2004 5:32 AM PS
By: Alvin Bruney [MVP] (search by author) In: microsoft.public.dotnet.framework.aspne
Your post went unanswered. Have you resolved this issue? If you still nee
help, please post the original question with your request

--
Regards
Alvin Bruney [ASP.NET MVP
Got tidbits? Get it here..
http://tinyurl.com/3he3
John McDonagh said:
I have a button column in a datagrid. When a button is clicked on I wan
it to use it's value as a variable a new SQL query that will repopulate th
datagridthe datagrid is rebound in the page_load method. Apart from bein
inefficient it also causes duplicate columns in my datagrid
The problem is that I have a dynamically created ButtonColumn in a DataGrid. Clicking on the ButtonColumn does not seem to raise the ItemCommand method unless I rebind the DataGrid in the Page_Load method. This is not a good solution for me as it is inefficient and causes duplicate rows (I want to rebind the datagrid in the ItemCommand method according to which Button in the ButtonColumn was clicked

I've posted this question a few times and found that lots of other people have posted the same problem. It seems very common but I've yet to see any explanation for it
 
S

Stanley

You don't have to do your databind call from your page load. You can instead
create a method (i call mine BindData) and do your binding there. By doing
this you can check for IsPostBack in your Page_Load method and only bind if
it is not a post back. Then in your button click method you can call for
binding again simply by calling your BindData method. If you want to do
sorting and filtering I suggest you store this stuff in the viewstate so
that you can get at it from your BindData method.

HTH

-Stanley


John McDonagh said:
Subject: Re: ButtonColumn postback problem 3/9/2004 5:32 AM PST
By: Alvin Bruney [MVP] (search by author) In: microsoft.public.dotnet.framework.aspnet
Your post went unanswered. Have you resolved this issue? If you still need
help, please post the original question with your request.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
John McDonagh said:
I have a button column in a datagrid. When a button is clicked on I
want
it to use it's value as a variable a new SQL query that will repopulate the
datagrid.
if
the datagrid is rebound in the page_load method. Apart from being
inefficient it also causes duplicate columns in my datagrid.
The problem is that I have a dynamically created ButtonColumn in a
DataGrid. Clicking on the ButtonColumn does not seem to raise the
ItemCommand method unless I rebind the DataGrid in the Page_Load method.
This is not a good solution for me as it is inefficient and causes duplicate
rows (I want to rebind the datagrid in the ItemCommand method according to
which Button in the ButtonColumn was clicked.
I've posted this question a few times and found that lots of other people
have posted the same problem. It seems very common but I've yet to see any
explanation for it.
 
S

Stanley

Show me your code for the datagrid and your ItemCommand method. As long as
the button is in the datagrid and your event is wired up correctly then it
should fire.

-Stanley

John McDonagh said:
Yes but if I don't call BindData in the Page_Load method then the
ItemCommand method is not raised - that's the problem I'm trying to
describe.
 
G

Guest

like I said, the ItemCommand method only fires if BindDataGrid(); is inluded in the Page_Load method

public void ResultsDataGrid_Command(object source, DataGridCommandEventArgs e


DisplayLabel.Text=e.Item.Cells[2].Text.ToString().Trim()
BindDataGrid()


BindDataGrid(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top