Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 1st, 2005, 04:21 AM
Authorized User
 
Join Date: Aug 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default read value from datagrid

i have a question regarding datagrid,i have a datagrid that reads from sql table and i want to know how to display a value from a cell(groupid) into a label at the same page or when moving to another linked page ....here is my code
---------------------------------
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<HTML>
    <script language="VB" runat="server">

Sub Page_Load(Source as Object, e as EventArgs)

    if not Page.IsPostBack then

        BindData
    End If
End Sub

Sub BindData()
    Dim strConn as string = "data source=lfr;uid=asw;pwd=;database=w"
    Dim sql as string = "Select username, password1, groupId from member"
    Dim conn as New SQLConnection(strConn)
    Dim Cmd as New SQLCommand(sql, conn)
    Dim myreader as SQLDataReader
    conn.Open()
    myreader=cmd.executereader()
    datagrid1.datasource=myreader
    datagrid1.databind()
    conn.Close()

End Sub

Sub Item_Created(sender As Object, e As DataGridItemEventArgs)

        Label1.Text = Label1.Text & " " & e.item.ItemIndex
    End Sub
     </script>
    <form runat="server">
        <asp:datagrid id="DataGrid1" runat="server"></asp:datagrid>
        <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</P>
        <P><asp:label id="Label1" runat="server"></asp:label></P>
        <P>&nbsp;</P>
    </form>
</HTML>

 
Old March 1st, 2005, 02:04 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I am slighlty unclear as to what you want to do. Here is how you can assign a value to a label from a datagrid cell"

Label1.Text = DataGrid1.Items(0).Cells(0).Text()

You need to know the index of the row and column you want to pull from.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Only Form Is not Read only lryckman Access VBA 3 June 12th, 2007 06:30 AM
Can't read values from editable datagrid collie ASP.NET 1.x and 2.0 Application Design 5 May 9th, 2007 11:16 AM
make two colums read only in updatable datagrid noor ASP.NET 1.0 and 1.1 Basics 1 May 11th, 2005 09:44 AM
Can't read new data from DataGrid cell Guest00 ASP.NET 1.0 and 1.1 Basics 3 October 17th, 2004 11:51 PM
Read cell in the DataGrid? drasko ASP.NET 1.0 and 1.1 Professional 1 December 18th, 2003 10:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.