Requesting Datagrid.Items.Count???

Posted on 2005-04-26
Last Modified: 2012-08-13

i have an ASPX page which submits all of its contents to another ASPX page so they can be insert into an SQL database.

I am trying to get the Datagrid.Items.Count throug Request.Form(Datagrid.Items.Count) but it doesn't seem to work.

Any suggestions??

Thank you.
Question by:Globemaster
    LVL 20

    Accepted Solution

    Is Enableviewstate= true  on your dg ?

    Author Comment

    Yes , EnableViewState is true for the Datagrid.
    LVL 20

    Expert Comment

    Can I see your  code pls

    Author Comment

    This is the first Page where i define the Datagrid and populate the data from the SQL server to the DataGrid.

    <TD align="center" colSpan="4"><asp:datagrid id="DataGrid2" runat="server" Width="100%" Font-Names="Tahoma" Font-Size="XX-Small" EnableViewState="True" CellPadding="4" HeaderStyle-BackColor="Black" HeaderStyle-ForeColor="White" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" OnDeleteCommand="DataGrid2_Delete" OnUpdateCommand="DataGrid2_Update" OnCancelCommand="DataGrid2_Cancel" AutoGenerateColumns="False">
    <HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="Black"></HeaderStyle>
                                                    <asp:BoundColumn DataField="PartnerID" HeaderText="PartnerID" ReadOnly="True"></asp:BoundColumn>
                                                    <asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
                                                    <asp:BoundColumn DataField="Country" HeaderText="Country"></asp:BoundColumn>


    This is the code-behind of the first page:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            If Not IsPostBack Then show()

    End Sub

    Private Sub show()

            'Dim da As New SqlDataAdapter
            Dim conn As New SqlConnection(Application("SQL_CONNECTION_STRING"))

            Dim cmd As New SqlCommand("Select * from External_Partners", conn)
            Dim objDR As SqlDataReader
            objDR = cmd.ExecuteReader()
            Datagrid2.DataSource = objDR

    End Sub

    Now this is the 2nd page (VB code) in which i wish to get the Datagrid.Items.count

    Dim cmdProj_Part As New SqlCommand("Insert into Proj_ExtPartner (ProjectID,PartnerID) values (@ProjectID,@PartnerID) ", conn)
            cmdProj_Part.Parameters.Add("@ProjectID", SqlDbType.Int)
            cmdProj_Part.Parameters.Add("@PartnerID", SqlDbType.Int)

            Dim i As Integer

            Label1.Text = Context.Items("retID")
            For i = 0 To Request.Form("DataGrid2.Items.Count") - 1
            cmdProj_Part.Parameters("@ProjectID").Value = retProjectID
            cmdProj_Part.Parameters("@PartnerID").Value = Request.Form("DataGrid2.Items(i).Cells(1).Text")

    Basically i am trying to get each dataGrid row ID so i can enter it a SQL table.


    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now