Windows Develop Bookmark and Share   
 index > Windows Forms General > Passing a Parameter in a DataGrid ButtonColumn
 

Passing a Parameter in a DataGrid ButtonColumn

Greetings,

I am using a DataGrid to display advertisements on a ad board. All works great, except on day 2, the links that were visited show visited today.

The culprit is that the control links that are really a ButtonColumn are rendered with;

href=__doPostBack('DataGrid1$_ctl7$_ctl0','')" and the next day there are mor of these same links.

Ideally I would like to set the eventArgument parameter, to a unique ID to have something like...

href=__doPostBack('DataGrid1$_ctl7$_ctl0','37452')"

In this way each Item would be Unique. 

I have thought about modifying the Render which seems like it would be simple enough but I have heard there are problems with ButtonColumns rendering properly.  

I also tried to set the "OnClick" event manually myself for a while, but that did not help as the control still showed href=__doPostBack('DataGrid1$_ctl7$_ctl0','')". I also can replace it with a Web Link, but the way my code works that would generate a lot of overhead.

Thoughts?

Is there a way to set the eventArgument?

DevonSprings  Saturday, August 20, 2005 11:54 PM
As far as I know, you can't set the commandargument on a button column

What you could do is use a template column instead of the button column.  You could place a button or a linkbutton inside the template column and set the commandargument to a value coming from either the datasource or your code.  Then you could use the ItemCommand event to do something with the click.

<Columns>

<asp:TemplateColumn HeaderText="Some Button">
   <ItemTemplate>
   <asp:LinkButton id="LinkButton1" runat="server" CommandArgument='
<# Eval   ("SomeDatabaseField") %>' >LinkButton</asp:LinkButton>
   </ItemTemplate>
</asp:TemplateColumn>

</Columns>


Hope this helps
Jason K  Sunday, August 21, 2005 5:27 AM
Jason,

Great idea, but not quite it. Basically I only need to add the parameter so that each link is Unique. I don't really need the parameter at all.

I think I am going to go to a Link, and see if I can fake sending the right stuff back.

Thank you for your try.

All the best,

regards:jamie
DevonSprings  Sunday, August 21, 2005 6:33 PM

Sorry, I guess I misinterpreted what you wanted.  Do you basically need the html of the link itself to be unique or do you need a unique value when you do something with the event?


Good luck,

Jason

Jason K  Monday, August 22, 2005 2:30 AM
Jason,

I need the HTML to be unique, so that people will know which link they went to over days and days of time.

regards:jamie
DevonSprings  Thursday, August 25, 2005 12:00 AM
Sorry for the not responding sooner,


Would adding a custom attribute to a linkbutton or link work?  You could create a custom linkbutton and add an additional attribute to it.  It would make a link with unique html.

you could get a link like:

<a href="__doPostBack('_ctl0','')" MyCustomAttribute="SomeUniqueValue">MyLinkButton</a>


Jason
Jason K  Wednesday, August 31, 2005 5:56 AM

You can use google to search for other answers

Custom Search

More Threads

• Colorizing Tab Control w/o redrawing
• can any one help me
• Can't stop the beep when pressing enter
• press keyboard "enter" key
• Email: get text into body and send automatically
• Complete Width of a DataGridViewCell
• Drawing in a Panel
• How to scoll DataGridView vertically in pixels?
• why use sql express
• Stop Cut/Copy in Text Box