I tried this message on another forum to no avail. I see there are more messages here--I hope someone can help. I would have thought it would be simple to read values from cells on datagrids but I guess not. I got some things to try on another forum but nothing worked, someone please tell me there's a way to read from cells on datagrids from any sub. I want to access values when I'm in the OnSelectedIndexChanged sub which doesn't support datagrid item event args but there must be way to access cell values from datagrids anyway is there?<BR><BR>I've read through tons of sample ASP.NET code and cannot find a sample where it's done when without using Datatables and Datarows. In my sample below I have a sub where I would like to accecs the value of the "master_id" in the daMaster datagrid and have a sample of code that doestn't work but you should be able to tell from it what I'm attempting to accomplish. The grids are displaying fine on the form and I know there must be a way I can access the values from the cells. <BR><BR>Dim myDataSet As New DataSet <BR>Dim daMaster As SQLDataAdapter <BR>Dim daDetail As SQLDataAdapter <BR>Dim conSQL As String <BR><BR>conSQL ="server=local;database=myDatabase;uid=sa" <BR><BR>daMaster = New SQLDataAdapter("Select * From master", conSQL) <BR>daMaster.fill(dsChambers, "chamber_area") <BR>dgMaster.DataSource = myDataSet.Tables("master") <BR><BR>daDetail = New SQLDataAdapter("Select * From detail", conSQL) <BR>daDetail.fill(myDataSet, "detail") <BR>dgDetail.DataSource = myDataSet.Tables("detail") <BR><BR>dgMaster.DataBind() <BR>dgDetail.DataBind() <BR><BR>Sub Master_Index_Change(Source As Object,E AS EventArgs) <BR> 'This doesn't work but it is what I would like to be able to do<BR> myID = dgMaster.Tables("master").Row(SelectedRow).Column("master_id").Text()<BR>End SubThere's an example of how to do this at: ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwebuiwebcontrolsdatagridclassoneditcomm andtopic.htm (assuming you have the help docs installed locally). The code is as follows, with the important parts highlighted:<BR><BR><%@ Import Namespace="System.Data" %><BR> <BR><html><BR><BR> <script language="VB" runat="server"><BR> <BR> Dim Cart As New DataTable()<BR> Dim CartView As DataView<BR> Sub Page_Load(sender As Object, e As EventArgs)<BR> Dim dr As DataRow<BR> <BR> If Session("ShoppingCart") Is Nothing Then<BR> <BR> Cart.Columns.Add(New DataColumn("Qty", GetType(String)))<BR> Cart.Columns.Add(New DataColumn("Item", GetType(String)))<BR> Cart.Columns.Add(New DataColumn("Price", GetType(String)))<BR> Session("ShoppingCart") = Cart<BR> <BR> ' Create some rows and insert some sample data.<BR> Dim i As Integer<BR> For i = 1 To 4<BR> dr = Cart.NewRow()<BR> If i Mod 2 <> 0 Then<BR> dr(0) = "2"<BR> Else<BR> dr(0) = "1"<BR> End If<BR> dr(1) = "Item " + i.ToString()<BR> dr(2) =(1.23 *(i + 1)).ToString()<BR> Cart.Rows.Add(dr)<BR> Next i<BR> Else<BR> Cart = CType(Session("ShoppingCart"), DataTable)<BR> End If <BR> CartView = New DataView(Cart)<BR> CartView.Sort = "Item"<BR> <BR> If Not IsPostBack Then<BR> BindGrid()<BR> End If <BR> End Sub 'Page_Load<BR><BR><BR> Sub MyDataGrid_Edit(sender As Object, e As DataGridCommandEventArgs)<BR> MyDataGrid.EditItemIndex = e.Item.ItemIndex<BR> BindGrid()<BR> End Sub 'MyDataGrid_Edit<BR><BR><BR> Sub MyDataGrid_Cancel(sender As Object, e As DataGridCommandEventArgs)<BR> MyDataGrid.EditItemIndex = - 1<BR> BindGrid()<BR> End Sub 'MyDataGrid_Cancel<BR><BR><BR> Sub MyDataGrid_Update(sender As Object, e As DataGridCommandEventArgs)<BR> ' For bound columns, the edited value is stored in a TextBox.<BR> ' The TextBox is the 0th element in the column's cell.<BR> Dim qtyText As TextBox = CType(e.Item.Cells(2).Controls(0), TextBox)<BR> Dim priceText As TextBox = CType(e.Item.Cells(3).Controls(0), TextBox)<BR> <BR> Dim item As String = e.Item.Cells(1).Text<BR> Dim qty As String = qtyText.Text<BR> Dim price As String = priceText.Text<BR> <BR> Dim dr As DataRow<BR> ' With a database, use an update command to update the data. Because <BR> ' the data source in this example is an in-memory DataTable, delete the <BR> ' old row and replace it with a new one.<BR><BR> ' Remove old entry.<BR> CartView.RowFilter = "Item='" & item & "'"<BR> If CartView.Count > 0 Then<BR> CartView.Delete(0)<BR> End If<BR> CartView.RowFilter = ""<BR> <BR> ' Add new entry.<BR> dr = Cart.NewRow()<BR> dr(0) = qty<BR> dr(1) = item<BR> dr(2) = price<BR> Cart.Rows.Add(dr)<BR> <BR> MyDataGrid.EditItemIndex = - 1<BR> BindGrid()<BR> End Sub 'MyDataGrid_Update<BR><BR><BR> Sub BindGrid()<BR> MyDataGrid.DataSource = CartView<BR> MyDataGrid.DataBind()<BR> End Sub 'BindGrid<BR> <BR> </script><BR> <BR><body><BR> <BR> <form runat="server"><BR><BR> <h3>DataGrid Editing Example</h3><BR> <BR> <asp
ataGrid id="MyDataGrid" runat="server"<BR> BorderColor="black"<BR> BorderWidth="1"<BR> CellPadding="3"<BR> Font-Name="Verdana"<BR> Font-Size="8pt"<BR> OnEditCommand="MyDataGrid_Edit"<BR> OnCancelCommand="MyDataGrid_Cancel"<BR> OnUpdateCommand="MyDataGrid_Update"<BR> AutoGenerateColumns="false"><BR><BR> <HeaderStyle BackColor="#aaaadd"><BR> </HeaderStyle><BR> <BR> <Columns><BR> <asp:EditCommandColumn<BR> EditText="Edit"<BR> CancelText="Cancel"<BR> UpdateText="Update"<BR> HeaderText="Edit Command Column"><BR><BR> <ItemStyle Wrap="false"><BR> </ItemStyle><BR><BR> <HeaderStyle Wrap="false"><BR> </HeaderStyle><BR><BR> </asp:EditCommandColumn><BR> <BR> <asp:BoundColumn HeaderText="Item" ReadOnly="true" DataField="Item"/><BR> <asp:BoundColumn HeaderText="Quantity" DataField="Qty"/><BR> <asp:BoundColumn HeaderText="Price" DataField="Price"/><BR> </Columns><BR> </asp
ataGrid><BR> <BR> </form><BR> <BR></body><BR></html>The example I'm replying to shows how to get the column values for a particular DataGrid control row when the row is selected via the EditIndex property and the user has selected to Update the changes.<BR><BR>If you just have a regular DataGrid, you can interrogate the DataGrid's Items property and do the same thing, essentially. See: ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwebuiwebcontrolsdatagridclassitemstopic .htm<BR><BR> Sub Button_Click(sender As Object, e As EventArgs)<BR> <BR> Dim item As DataGridItem<BR> For Each item In ItemsGrid.Items<BR> Label1.Text &= "<BR>" & item.Cells(0).Text & _<BR> " " & item.Cells(1).Text & _<BR> " " & item.Cells(2).Text<BR> Next item<BR> End Sub 'Button_Click<BR><BR>The Cells is a zero-indexed collection of the columns in a DataGrid's row. hthThanks for responding Scott though that was not quite what I was looking for either but it was close. I finally found what I was looking for on MSDN though. It's is as simple as this to access cell values from a Sub that doesn't have the Item passed in : MyDataGrid.SelectedItem.Cells(1).Text <BR><BR>

