Solved

Printing selected Records from a Gridview

Posted on 2008-10-15
3
795 Views
Last Modified: 2013-12-17
Not sure if this is possible, but I have a GridView with checkboxes at the moment. I want to somehow have the user be able to just print those selected records. Here is the code below.
<%@ Page Language="C#" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
 
<head runat="server">
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type" />
<title>Results Page</title>
 
<style type="text/css">
.style1 {
	font-size: xx-large;
}
.style2 {
	text-align: center;
}
</style>
 
 
 
</head>
<script language="javascript">
 
 function SelectAllCheckboxes(spanChk){
 
   // Added as ASPX uses SPAN for checkbox
 
   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? 
        spanChk : spanChk.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;
 
   for(i=0;i<elm.length;i++)
     if(elm[i].type=="checkbox" && 
              elm[i].id!=theBox.id)
     {
       //elm[i].click();
 
       if(elm[i].checked!=xState)
         elm[i].click();
       //elm[i].checked=xState;
 
     }
 }
</script>
 
<body>
<h3><a href="../index.htm">Home</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="SubmitForm.aspx">Back to Submission Page</a></h3>
<p class="style1">LA Database Results Page</p>
 
<form id="form2">
	<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:LA_DBASEConnectionString %>" SelectCommand="SELECT COUNT(Date_Ini), COUNT(Date_Resolved), COUNT(Date_update)  FROM [MainLATable]
">
</asp:SqlDataSource>
		<div class="style2">
			<asp:ListView id="ListView1" runat="server" DataSourceID="SqlDataSource2">
		<ItemTemplate>
			<tr style="background-color:#DCDCDC;color: #000000;">
				<td>
				<asp:label id="Column1Label" runat="server" Text='<%# Eval("Column1") %>' />
				</td>
				<td>
				<asp:label id="Column2Label" runat="server" Text='<%# Eval("Column2") %>' />
				</td>
				<td>
				<asp:label id="Column3Label" runat="server" Text='<%# Eval("Column3") %>' />
				</td>
			</tr>
		</ItemTemplate>
		<AlternatingItemTemplate>
			<tr style="background-color:#FFF8DC;">
				<td>
				<asp:label id="Column1Label"  runat="server" Text='<%# Eval("Column1") %>' />
				</td>
				<td>
				<asp:label id="Column2Label" runat="server" Text='<%# Eval("Column2") %>' />
				</td>
				<td>
				<asp:label id="Column3Label" runat="server" Text='<%# Eval("Column3") %>' />
				</td>
			</tr>
		</AlternatingItemTemplate>
		<EmptyDataTemplate>
			<table runat="server" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
				<tr>
					<td>No data was returned.</td>
				</tr>
			</table>
		</EmptyDataTemplate>
		<InsertItemTemplate>
			<tr style="">
				<td>
				<asp:button id="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
				<asp:button id="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
				</td>
				<td>
				<asp:textbox id="Column1TextBox" runat="server" Text='<%# Bind("Column1") %>' />
				</td>
				<td>
				<asp:textbox id="Column2TextBox" runat="server" Text='<%# Bind("Column2") %>' />
				</td>
				<td>
				<asp:textbox id="Column3TextBox" runat="server" Text='<%# Bind("Column3") %>' />
				</td>
			</tr>
		</InsertItemTemplate>
		<LayoutTemplate>
			<table runat="server">
				<tr runat="server">
					<td runat="server">
					<table ID="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
						<tr runat="server" style="background-color:#DCDCDC;color: #000000;">
							<th runat="server">Problem Initiated Count&nbsp;&nbsp;&nbsp;&nbsp;</th>
							<th runat="server">Resolution Count&nbsp;&nbsp;&nbsp;&nbsp;</th>
							<th runat="server">GIS Updated Count</th>
						</tr>
						<tr ID="itemPlaceholder" runat="server">
						</tr>
					</table>
					</td>
				</tr>
				<tr runat="server">
					<td runat="server" style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
					</td>
				</tr>
			</table>
		</LayoutTemplate>
		<EditItemTemplate>
			<tr style="background-color:#008A8C;color: #FFFFFF;">
				<td>
				<asp:button id="UpdateButton" runat="server" CommandName="Update" Text="Update" />
				<asp:button id="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
				</td>
				<td>
				<asp:textbox id="Column1TextBox" runat="server" Text='<%# Bind("Column1") %>' />
				</td>
				<td>
				<asp:textbox id="Column2TextBox" runat="server" Text='<%# Bind("Column2") %>' />
				</td>
				<td>
				<asp:textbox id="Column3TextBox" runat="server" Text='<%# Bind("Column3") %>' />
				</td>
			</tr>
		</EditItemTemplate>
		<SelectedItemTemplate>
			<tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
				<td>
				<asp:label id="Column1Label" runat="server" Text='<%# Eval("Column1") %>' />
				</td>
				<td>
				<asp:label id="Column2Label" runat="server" Text='<%# Eval("Column2") %>' />
				</td>
				<td>
				<asp:label id="Column3Label" runat="server" Text='<%# Eval("Column3") %>' />
				</td>
			</tr>
		</SelectedItemTemplate>
</asp:ListView>
		</div>
</form>
 
 
<form id="form1" runat="server">
&nbsp;<asp:GridView id="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="3" DataKeyNames="ID" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical" PageSize="15" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px">
		<FooterStyle BackColor="#CCCCCC" />
		<Columns>
      <asp:TemplateField HeaderText="Select">
    <ItemTemplate>
       <asp:CheckBox ID="chkSelect" runat="server" />
    </ItemTemplate>
    <HeaderTemplate>
    <input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" 
              runat="server" type="checkbox" />
    </HeaderTemplate>
   </asp:TemplateField>
 
			<asp:commandfield ShowDeleteButton="True" ShowEditButton="True">
			</asp:commandfield>
			<asp:boundfield DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID">
			</asp:boundfield>
			<asp:boundfield DataField="Rank_Main" HeaderText="Rank_Main" SortExpression="Rank_Main">
			</asp:boundfield>
			<asp:boundfield DataField="Mapper_Main" HeaderText="Mapper_Main" SortExpression="Mapper_Main">
			</asp:boundfield>
			<asp:boundfield DataField="State_Main" HeaderText="State_Main" SortExpression="State_Main">
			</asp:boundfield>
			<asp:boundfield DataField="County_Main" HeaderText="County_Main" SortExpression="County_Main">
			</asp:boundfield>
			<asp:boundfield DataField="GIS_Ref" HeaderText="GIS_Ref" SortExpression="GIS_Ref">
			</asp:boundfield>
			<asp:boundfield DataField="Agmnt_No" HeaderText="Agmnt_No" SortExpression="Agmnt_No">
			</asp:boundfield>
			<asp:boundfield DataField="Tract_Nos" HeaderText="Tract_Nos" SortExpression="Tract_Nos">
			</asp:boundfield>
			<asp:boundfield DataField="Control_Stmnt" HeaderText="Control_Stmnt" SortExpression="Control_Stmnt">
			</asp:boundfield>
			<asp:boundfield DataField="Problem" HeaderText="Problem" SortExpression="Problem">
			</asp:boundfield>
			<asp:boundfield DataField="Resolution" HeaderText="Resolution" SortExpression="Resolution">
			</asp:boundfield>
			<asp:boundfield DataField="Date_Ini" HeaderText="Date_Ini" SortExpression="Date_Ini">
			</asp:boundfield>
			<asp:boundfield DataField="Date_Resolved" HeaderText="Date_Resolved" SortExpression="Date_Resolved">
			</asp:boundfield>
			<asp:boundfield DataField="Date_update" HeaderText="Date_update" SortExpression="Date_update">
			</asp:boundfield>
		</Columns>
		<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
		<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
		<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
		<AlternatingRowStyle BackColor="#CCCCCC" />
	</asp:GridView>
	<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LA_DBASEConnectionString %>" DeleteCommand="DELETE FROM [MainLATable] WHERE [ID] = @ID" InsertCommand="INSERT INTO [MainLATable] ([Rank_Main], [Mapper_Main], [State_Main], [County_Main], [GIS_Ref], [Agmnt_No], [Tract_Nos], [Control_Stmnt], [Problem], [Resolution], [Date_Ini], [Date_Resolved], [Date_update]) VALUES (@Rank_Main, @Mapper_Main, @State_Main, @County_Main, @GIS_Ref, @Agmnt_No, @Tract_Nos, @Control_Stmnt, @Problem, @Resolution, @Date_Ini, @Date_Resolved, @Date_update)" SelectCommand="SELECT * FROM [MainLATable]" UpdateCommand="UPDATE [MainLATable] SET [Rank_Main] = @Rank_Main, [Mapper_Main] = @Mapper_Main, [State_Main] = @State_Main, [County_Main] = @County_Main, [GIS_Ref] = @GIS_Ref, [Agmnt_No] = @Agmnt_No, [Tract_Nos] = @Tract_Nos, [Control_Stmnt] = @Control_Stmnt, [Problem] = @Problem, [Resolution] = @Resolution, [Date_Ini] = @Date_Ini, [Date_Resolved] = @Date_Resolved, [Date_update] = @Date_update WHERE [ID] = @ID">
		<DeleteParameters>
			<asp:parameter Name="ID" Type="Int32" />
		</DeleteParameters>
		<UpdateParameters>
			<asp:parameter Name="Rank_Main" Type="String" />
			<asp:parameter Name="Mapper_Main" Type="String" />
			<asp:parameter Name="State_Main" Type="String" />
			<asp:parameter Name="County_Main" Type="String" />
			<asp:parameter Name="GIS_Ref" Type="String" />
			<asp:parameter Name="Agmnt_No" Type="String" />
			<asp:parameter Name="Tract_Nos" Type="String" />
			<asp:parameter Name="Control_Stmnt" Type="String" />
			<asp:parameter Name="Problem" Type="String" />
			<asp:parameter Name="Resolution" Type="String" />
			<asp:parameter Name="Date_Ini" Type="DateTime" />
			<asp:parameter Name="Date_Resolved" Type="DateTime" />
			<asp:parameter Name="Date_update" Type="DateTime" />
			<asp:parameter Name="ID" Type="Int32" />
		</UpdateParameters>
		<InsertParameters>
			<asp:parameter Name="Rank_Main" Type="String" />
			<asp:parameter Name="Mapper_Main" Type="String" />
			<asp:parameter Name="State_Main" Type="String" />
			<asp:parameter Name="County_Main" Type="String" />
			<asp:parameter Name="GIS_Ref" Type="String" />
			<asp:parameter Name="Agmnt_No" Type="String" />
			<asp:parameter Name="Tract_Nos" Type="String" />
			<asp:parameter Name="Control_Stmnt" Type="String" />
			<asp:parameter Name="Problem" Type="String" />
			<asp:parameter Name="Resolution" Type="String" />
			<asp:parameter Name="Date_Ini" Type="DateTime" />
			<asp:parameter Name="Date_Resolved" Type="DateTime" />
			<asp:parameter Name="Date_update" Type="DateTime" />
		</InsertParameters>
	</asp:SqlDataSource>
	</form>
	
	
 
</body>
 
</html>

Open in new window

0
Comment
Question by:GravitaZ24
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 500 total points
ID: 22724969
Hi,

I would use css in this case and when the grid is bound or and event is triggered eg if a checkbox is checked/unchecked then attach the css class to the table row of the gridview - are you ok to move on from here?
0
 

Author Comment

by:GravitaZ24
ID: 22725051
Thanks,
Not particularly, I'm kind of a newbie with ASP.NET. I understand CSS. I've seen examples of them making a second print page but didn't quite understand it. Is that kind of how it would work?
0
 

Author Comment

by:GravitaZ24
ID: 22789948
I figured it out, I just did a DIV and printed the gridview. Thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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