Link to home
Start Free TrialLog in
Avatar of Globemaster
Globemaster

asked on

Requesting Datagrid.Items.Count???

Hello,

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.
ASKER CERTIFIED SOLUTION
Avatar of jitganguly
jitganguly

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Globemaster
Globemaster

ASKER

Yes , EnableViewState is true for the Datagrid.
Can I see your  code pls
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>
                                          
<Columns>
                                                <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>

</Columns>
</asp:datagrid></TD>


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
        conn.Open()
        objDR = cmd.ExecuteReader()
        Datagrid2.DataSource = objDR
        DataGrid2.DataBind()
        conn.Close()

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")
        conn.Open()
        cmdProj_Part.ExecuteNonQuery()
        conn.Close()
        Next

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