Retrieve data in a datagrid

James

Well-known member
Joined
Oct 3, 2002
Messages
78
Does anyone know what property I can use to retrieve the value in a datagrid cell? Below I have a button column that has a "Select" link. When I click it I want to retrieve a value in one of the columns and assign it to a variable. Can someone help. Thanks

James



<asp:DataGrid id="lstResults" runat="server" Visible="False" PageSize="100" AutoGenerateColumns="False" Width="60%" HorizontalAlign="Center" CellPadding="0">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="Select" CommandName="Select">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Top"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:ButtonColumn>
<asp:BoundColumn DataField="twp" HeaderText="TWP">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="wbs" HeaderText="WBS">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Resource" HeaderText="Resource">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="camname" HeaderText="CAM Name">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="boe" HeaderText="BOE Desc">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Wrap="True" VerticalAlign="Top"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
 
Ok I got it to work. What I did was I change the button column to a EditCommand Column and name the edit text "Select." When the "Select" link was press I placed the record in edit mode then I assign the variables with values form the textboxes. I did not disable the edit mode since I redirected the user. If you want you can disable the edit mode on the last line. The user will never know that it was in edit mode. Codes below.

Public Sub grdResults_Edit(ByVal Source As Object, ByVal E As DataGridCommandEventArgs)

lstResults.EditItemIndex = E.Item.ItemIndex
BindData()

Session("TWP") = E.Item.Cells(2).Text
Session("WBS") = E.Item.Cells(3).Text
Session("Resource") = E.Item.Cells(5).Text
Session("search") = "T"
If E.CommandSource.text = "Detail" Then
Response.Redirect("LaborDetails.aspx")

Else
Response.Redirect("NewLaborEst.aspx")
End If
End Sub

James
 
Back
Top