will someone please help me with this. It seems simple enough but I'm very new to asp and vb. I have a datagrid and I want to know how to access the values in a specific column. The dg is bound to a sql query. The column returns integer values in sql. I want to be able to sum the column and have a button_click command send the datagrid values to 0. I only want to change the datagrid values NOT the sql values (I currently have an Update/Set sql command in vb for this but as I said I only want the Datagrid values to change). Simply put where, if anywhere are the datagrid values stored? I have the column set as a template column and the items are displayed in the datagrid as textboxes (to allow the cells in this column to be changed). can someone please help or at least tell me if this question makes any sense. thank you

Recommended Answers

All 3 Replies

You can access a perticular colum in dataset by
ds.Tables[0].Rows[0]["Columnname"].ToString()

You can access a particular column of gridview in its Rowdatabound event

Hope one of it may help u

will someone please help me with this. It seems simple enough but I'm very new to asp and vb. I have a datagrid and I want to know how to access the values in a specific column. The dg is bound to a sql query. The column returns integer values in sql. I want to be able to sum the column and have a button_click command send the datagrid values to 0. I only want to change the datagrid values NOT the sql values (I currently have an Update/Set sql command in vb for this but as I said I only want the Datagrid values to change). Simply put where, if anywhere are the datagrid values stored? I have the column set as a template column and the items are displayed in the datagrid as textboxes (to allow the cells in this column to be changed). can someone please help or at least tell me if this question makes any sense. thank you

I am able to return all the values of the datagrid except the last column (item.cells(6).text). The vb looks like this

For Each item In DataGrid1.Items
            Label1.Text &= "<br />" & item.Cells(0).Text & _
                        " " & item.Cells(1).Text & _
                        " " & item.Cells(2).Text & _
                        " " & item.Cells(3).Text & _
                        " " & item.Cells(4).Text & _
                        " " & item.Cells(5).Text & _
                        " " & item.Cells(6).Text

        Next item

The difference with this column in the asp is that the values returned from the sql query are placed into editable text boxes. the asp for the datagrid is here

<asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="False" BackColor="White"
                                    BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
                                <SelectedItemStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" />
                                <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                                <Columns>
                                    <asp:BoundColumn DataField="Order_Line" HeaderText="Line"></asp:BoundColumn>
                                    <asp:BoundColumn DataField="TN_CN_S_Desc" HeaderText="Description">
                                        <ItemStyle HorizontalAlign="Left" />
                                    </asp:BoundColumn>
                                    <asp:BoundColumn DataField="Item" HeaderText="Item"></asp:BoundColumn>
                                    <asp:BoundColumn DataField="Pack" HeaderText="Pack"></asp:BoundColumn>
                                    <asp:BoundColumn DataField="Location" HeaderText="Location"></asp:BoundColumn>
                                    <asp:BoundColumn DataField="Lot" HeaderText="Lot"></asp:BoundColumn>
                                    <asp:TemplateColumn HeaderText="# Labels">

                                        <ItemTemplate>
                                            <asp:TextBox runat="server" Style="text-align: right" Text='<%# DataBinder.Eval(Container.DataItem,"Label_Nb") %>'
                                                    Width="65"></asp:TextBox>
                                        </ItemTemplate>
                                        <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                                            Font-Underline="False" HorizontalAlign="Right" />
                                        <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                                            Font-Underline="False" HorizontalAlign="Right" />
                                    </asp:TemplateColumn>
                                    
                                </Columns>
                                <PagerStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                                    Font-Underline="False" HorizontalAlign="Left" />
                            </asp:DataGrid>

how am i to display the values from this template column?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.