Results 1 to 5 of 5

Thread: [02/03] Print Selected Rows in DataGrid

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    3

    [02/03] Print Selected Rows in DataGrid

    Hello All,

    I am a newbie to vb.net programming.
    I populated my datagrid with some data from the sql server. I also have a check box cloumn on the left.
    Now, I need to select a couple of rows and ONLY print the selected rows.

    How can i do this..?

    Please HELP.

    Thanks.

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: [02/03] Print Selected Rows in DataGrid

    Hi and welcome to the forum.
    Unfortunetly you cannot print directly the selection of rows, you have to use a report or a file and print them.
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    3

    Re: [02/03] Print Selected Rows in DataGrid

    Hey,

    Thanks for the info..

    This is my situation::::

    I have created a datagrid which I have bound to a SQL database, when I browse the form with the datagrid it displays all the columns as expected using the following code:

    Sub BindTheData()
    Dim objConn As SqlConnection
    Dim objCmd As SqlCommand
    objConn = New SqlConnection("server=localhost; uid=; password=; database=Northwind")
    Dim strSql As String
    strSql = "SELECT Top 10 CustomerID, CompanyName, ContactName, " _
    & "ContactTitle, City, Country, Phone FROM Customers"
    Try
    objCmd = New SqlCommand(strSql, objConn)
    objConn.Open()
    dtgCusts.DataSource = objCmd.ExecuteReader()
    dtgCusts.DataBind()
    Catch
    Finally
    If objConn.State = ConnectionState.Open Then
    objConn.Close()
    objConn.Dispose()
    End If
    End Try
    End Sub
    ---------------------------------------------------------------------
    <asp:datagrid id="dtgCusts" Runat="server" GridLines="Vertical" CellPadding="3" BackColor="White"
    BorderWidth="1px" BorderStyle="None" BorderColor="#999999" AutoGenerateColumns="False">
    <Columns>
    <asp:TemplateColumn HeaderText="Select" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:CheckBox ID="chkSelection" Runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Company Name">
    <ItemTemplate>
    <asp:Label ID="lblCompanyName" Text='<%# DataBinder.Eval(Container.DataItem,"CompanyName") %>' runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn HeaderText="Contact Name" DataField="ContactName" />
    <asp:BoundColumn HeaderText="Contact Title" DataField="ContactTitle" />
    <asp:BoundColumn HeaderText="City" DataField="City" />
    <asp:BoundColumn HeaderText="Country" DataField="Country" />
    <asp:BoundColumn HeaderText="Telephone" DataField="Phone" />
    <asp:BoundColumn HeaderText="Customer ID" DataField="CustomerID" Visible="False" />
    <asp:TemplateColumn HeaderText="CustomerID" Visible="False">
    <ItemTemplate>
    <asp:Label ID="lblCustomerID" Text='<%# DataBinder.Eval(Container.DataItem,"CustomerID") %>' Runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    <AlternatingItemStyle BackColor="#DCDCDC" />
    <ItemStyle ForeColor="Black" BackColor="#EEEEEE" />
    <headerStyle Font-Bold="True" ForeColor="White" BackColor="#000084" />
    </asp:datagrid>
    --------------------------------------------------------------------

    I now want to be able to select one/many rows by clicking the checkbox and then display the data from that selected rows in a new page and then print those rows.

    If possible, please send me a code/snippet which will do that trick.

    I would really appreciate a helping hand.

    Arun.

  4. #4
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: [02/03] Print Selected Rows in DataGrid

    Sorry but i have no experience with ASP.Net projects.
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    3

    Re: [02/03] Print Selected Rows in DataGrid

    No Problem..
    Thanks for the help..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width