[RESOLVED] handle fire event when row clicked in a datagrid
i want to edit the selected value in another page by click the row in the datagrid.
how can i pass the value? how can i call the other page?
i have this dgrid:
<asp:datagrid id="clientGrid" runat="server" cellPadding="5" PageSize="20" AutoGenerateColumns="False"
AllowSorting="True" Width="576px" AllowPaging="True" Height="144px">
<SelectedItemStyle Font-Size="XX-Small" Font-Names="Tahoma" Font-Bold="True" BackColor="WhiteSmoke"></SelectedItemStyle>
<AlternatingItemStyle Font-Size="XX-Small" Font-Names="Tahoma" BackColor="WhiteSmoke"></AlternatingItemStyle>
<ItemStyle Font-Size="XX-Small" Font-Names="Tahoma"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Names="Arial" HorizontalAlign="Center"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:linkbutton id="cmdView" runat="server">View</asp:linkbutton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:linkbutton id="cmdEdit" runat="server">Edit</asp:linkbutton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="CLIE_CODE" ReadOnly="True" HeaderText="CODE"></asp:BoundColumn>
<asp:BoundColumn DataField="CLIE_NAME" HeaderText="CLIENT NAME"></asp:BoundColumn>
<asp:BoundColumn DataField="CLIE_SENTBY" HeaderText="SENTBY"></asp:BoundColumn>
<asp:BoundColumn DataField="CLIE_ADDEDDATE" ReadOnly="True" HeaderText="DATE" DataFormatString="{0:d}"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:linkbutton id="cmdDelete" runat="server">Delete</asp:linkbutton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Font-Size="0.7em" Font-Names="Verdana" HorizontalAlign="Right" ForeColor="#FF0066"
Position="TopAndBottom" PageButtonCount="11" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
what i want is if i clicked the edit linkbutton i will get the row informatin and open the edit page for that id.
TIA :wave:
Re: handle fire event when row clicked in a datagrid
Rather than using item templates, use a buttoncolumn like this:
Code:
<asp:ButtonColumn ButtonType="LinkButton" Text="Edit" CommandName="Select"></asp:ButtonColumn>
When the user clicks on this you need to get the client that they clicked on. So what you need to do is to put this code in your <asp:datagrid> tag
Code:
OnItemCommand="viewRow" DataKeyField="CLIE_CODE"
You must then define this 'viewRow' event in your page behind. Something like this...
VB Code:
Public Sub viewRow(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
If Not e.Item.ItemIndex = -1 Then
'put code here
Dim ID as String = ctype(dgrGrid.DataKeys(e.Item.ItemIndex), string)
'etc....
End If
End Sub
dgrGrid.DataKeys(e.Item.ItemIndex) gives you the keyfield (CLIE_CODE) for the selected row that you specified in your <asp:datagrid> tag
I think thats about right :ehh:
Re: handle fire event when row clicked in a datagrid
Architecturally, you wouldn't want the server to have to post-back the form to take you to another page. The ID of the row (record what have you), should be in the link to the other page.
Your goal would be to have the html output look like this...
<a href="ItemEdit.aspx?id=123">Edit</a>
An anchor link will make the client Get a request for ItemEdit.aspx with the id parameter filled in.
A linkbutton has to post-back to the page that rendered the current response, wire everything up, then ascertain that the user clicked a button, fire your event handler, which would then initiate a response.redirect to ItemEdit.aspx. In a high-volume site, that would be just simple overkill.
As you can easily see, the former method is much faster.