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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Asp Button inside of a datagrid

Status
Not open for further replies.

kenbw

Programmer
May 2, 2002
39
US
Everyone,
I have a question. I have multiple datagrids within a datagrid and each of the inner datagrids needs to have an Asp Button. I can add the button and it looks good, but I cannot figure out how to wire them all up so that I can get an even fired when it posts back. Some help would be great.

Below is the how the datagrids are built:

<div id=&quot;div1&quot; style=&quot;OVERFLOW: auto; HEIGHT: 300px&quot;>
<asp:datagrid id=&quot;dgOrders&quot; Width=&quot;100%&quot; Runat=&quot;server&quot; ShowHeader=&quot;False&quot; CellPadding=&quot;0&quot; CellSpacing=&quot;0&quot; AutoGenerateColumns=&quot;false&quot;>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; border=&quot;1&quot; bordercolor=&quot;#999966&quot;>
<tr>
<td>
<table>
<tr>
<td class=&quot;FolderNameHeader&quot; style=&quot;WIDTH: 80pc&quot;>
<input type=&quot;checkbox&quot; onclick=&quot;CheckFolder(this)&quot; Runat=&quot;server&quot; ID=&quot;chkFolderSelect&quot; NAME=&quot;chkSelect&quot;></asp:CheckBox>  <b>Folder
Name:</b>  <%# DataBinder.Eval(Container.DataItem, &quot;OrderName&quot;) %>
</td>
<td class=&quot;FolderNameHeader&quot; style=&quot;TEXT-ALIGN: right&quot;>
<asp:button CommandName=&quot;btnAddNew_Click&quot; CommandArgument=<%# DataBinder.Eval(Container.DataItem, &quot;FXOrderId&quot;) %> id=&quot;BtnAddNew&quot; tabIndex=&quot;21&quot; runat=&quot;server&quot; CausesValidation=&quot;False&quot; CssClass=&quot;buttonred&quot; Text=&quot;Add&quot; Width=&quot;60px&quot;></asp:button></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align=&quot;right&quot;>
<asp:datagrid id=&quot;dgTransactions&quot; runat=&quot;server&quot; CssClass=&quot;textareagrid&quot; Width=&quot;100%&quot; AllowSorting=&quot;True&quot; HorizontalAlign=&quot;Center&quot; GridLines=&quot;Both&quot; AutoGenerateColumns=&quot;False&quot; DataKeyField=&quot;FXOrderId&quot; DataSource='<%# Container.DataItem.CreateChildView(&quot;FXOrderId&quot;) %>' BackColor=#CCCC99 OnEditCommand=&quot;dgTransactions_EditCommand&quot; BorderColor=&quot;999966&quot;>
<AlternatingItemStyle VerticalAlign=&quot;Top&quot; BackColor=&quot;#F1F1E6&quot;></AlternatingItemStyle>
<ItemStyle VerticalAlign=&quot;Top&quot; BackColor=&quot;White&quot;></ItemStyle>
<HeaderStyle Font-Size=&quot;XX-Small&quot; CssClass=&quot;headerrow&quot;></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType=&quot;LinkButton&quot; UpdateText=&quot;&quot; CancelText=&quot;&quot; EditText=&quot;Edit&quot;></asp:EditCommandColumn>
<asp:TemplateColumn>
<ItemTemplate>
<input type=&quot;checkbox&quot; onclick=&quot;UnCheck()&quot; runat=&quot;server&quot; id=&quot;chkSelect&quot; NAME=&quot;chkSelect&quot;>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible=&quot;False&quot; DataField=&quot;FXTransactionId&quot; ReadOnly=&quot;True&quot; HeaderText=&quot;Id&quot;></asp:BoundColumn>
<asp:BoundColumn Visible=&quot;False&quot; DataField=&quot;DateLastUpdated&quot;></asp:BoundColumn>
<asp:BoundColumn Visible=&quot;False&quot; DataField=&quot;FXTransactionStatusCodeId&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;JurisDesc&quot; ReadOnly=&quot;True&quot; HeaderText=&quot;UCC Financing Statement Description&quot;>
<ItemStyle ForeColor=&quot;#CC0033&quot;></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField=&quot;TransactionStatusDesc&quot; HeaderText=&quot;Status&quot;></asp:BoundColumn>
</Columns>
</asp:datagrid>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></div>

Thanks in advance for all the help.

Ken
 
This should handle it. I cut this from a page I am using...
<!-- in aspx -->
<ASP:BUTTON ID=&quot;btnAddNew&quot; ENABLED=&quot;False&quot; RUNAT=&quot;server&quot; TEXT=&quot;Add&quot; CAUSESVALIDATION=&quot;false&quot; OMMANDNAME=&quot;btnAddNew&quot;></ASP:BUTTON>

'Code behind / script
Public Sub Handle_Grid_Event(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs)

If e.CommandName = &quot;btnAddNew&quot; then
' do your code here
end if

end sub
 
That makes since, but how do you wire the button to the Handle_Grid_Event subrouting? I don't see the Handles portion?

Ken
 
Looked a bit further, my example was with in an edit item template.

The handles you need would be &quot;Handles [datagrid_name].ItemCommand&quot;

hth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top