Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dg ItemCommand not firing w/ ButtonColumn 1

Status
Not open for further replies.

KDavie

Programmer
Feb 10, 2004
441
US
This is driving me crazy!!!

I have a datagrid which uses the ItemCommand to run some code... When I try to use a ButtonColumn in the dg to fire the ItemCommand it doesn't work... However, when I use a template column and add a LinkButton to it the event fires fine... I want a PressButton instead of a LinkButton in the grid, as I need to access it's text property in code behind... My viewstate is enabled... I can't figure out why the command will fire for the linkbutton in a template column but not for a pressbutton in a buttoncolumn. Any ideas?
 
Can you supply an example page and it's code showing both methods you've used then we may be able to see what is wrong?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Sure....

In HTML
Code:
<asp:datagrid id="dgTestData" runat="server" Width="100%" ShowHeader="False">
<Columns>
	<asp:TemplateColumn><ItemStyle HorizontalAlign="Center"></ItemStyle>
		<ItemTemplate>
			<asp:LinkButton ID="lbSubmit" Runat="server" Text="<span style='text-decoration:none;'>+</span>"
			ForeColor="Blue"></asp:LinkButton>
		</ItemTemplate>
	</asp:TemplateColumn>
	<asp:ButtonColumn Text="+" ButtonType="PushButton" CommandName="Select"></asp:ButtonColumn>
</Columns>
</asp:datagrid></form>

Then in the item command of the grid create a variable and assign an arbitrary value to it:

Code:
Dim strTest as String = "Event Firing"
Set a breakpoint on it. When you run the app and click on the linkbutton then it will stop on the breakpoint, when you click the pushbutton the itemcommand event doesn't fire at all (no stop on breakpoint).
 
Although I still don't understand why I can't get this to work with a pushbutton, I was able to access the linkbutton's text property from code behind by specifying it's text this way:

Code:
<asp:LinkButton ID="lbSubmit" Runat="server" Text="<span style='text-decoration:none;'>+</span>"
            ForeColor="Blue"></asp:LinkButton>
instead of my original method:

Code:
<asp:LinkButton runat="server" Text="+" CommandName="Select" CausesValidation="false" ID="Linkbutton1"></asp:LinkButton><span style='text-decoration:none;'>+</span>

Although I would still like the look of a pushbutton over a linkbutton, the desired functionality is now in place.

-Kevin
 
Thanks tperri,

Works like a charm... A star for you!

-Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top