ButtonColumn

R

Roger

I have a datagrid with a ButtonColumn and a BoundColumn with a value.
Without showing the value, how can I make the button send back the value?
 
K

Ken Cox [Microsoft MVP]

Hi Roger,

By using a template column you can accomplish your goal without needing the
hidden BoundColumn at all. It is just a matter of putting the value into the
CommandArgument like this:


<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton runat="server" Text="Get Value"
CommandName="GetValue" CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "IntegerValue") %>'
CausesValidation="false">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
</form>

Then, when the button is clicked, you can pick up the value from the
CommandArgumentand do whatever you need to do:

Private Sub DataGrid1_ItemCommand _
(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls. _
DataGridCommandEventArgs) _
Handles DataGrid1.ItemCommand
If e.CommandName = "GetValue" Then
Label1.Text = e.CommandArgument.ToString
End If
End Sub

Ken
MVP [ASP.NET]
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top