Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Requesting Datagrid.Items.Count???

Posted on 2005-04-26
4
Medium Priority
?
246 Views
Last Modified: 2012-08-13
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.
0
Comment
Question by:Globemaster
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
jitganguly earned 200 total points
ID: 13867529
Is Enableviewstate= true  on your dg ?
0
 

Author Comment

by:Globemaster
ID: 13868437
Yes , EnableViewState is true for the Datagrid.
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 13868555
Can I see your  code pls
0
 

Author Comment

by:Globemaster
ID: 13869781
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.







0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 informatio…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

578 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