Solved

Printing selected Records from a Gridview

Posted on 2008-10-15
3
796 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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