Regarding checkbox for gridview

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
Can anyone please let me know.I have below code:
@asp:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"<br/>
CodeBehind="Default.aspx.cs" Inherits="Tool._Default" EnableEventValidation="false" %><br/>
<br/>
<%--<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="HeadContent <br/>
</asp:Content>--%><br/>
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="MainContent <br/>
<asp:Panel ID="pnlControls" runat="server <br/>
<table style="width: 364px <br/>
<tr><br/>
<td><br/>
<asp:Label ID="lblHeader" runat="server" Text="Report" Width="200px" CssClass="bold <br/>
</asp:Label><br/>
</td><br/>
</tr><br/>
</table><br/>
<table><br/>
<tr><br/>
<td><br/>
<asp:Label ID="lblShift" runat="server" Text="Shift:" Width="35px"<br/>
Height="16px </asp:Label>
<br/>
<asp:DropDownList ID="ddlShift" runat="server <br/>
<asp:ListItem Text="1st " Value="1 </asp:ListItem><br/>
<asp:ListItem Text="2nd " Value="2 </asp:ListItem><br/>
<asp:ListItem Text="3rd " Value="3 </asp:ListItem><br/>
</asp:DropDownList><br/>
</td> <br/>
</tr> <br/>
<td colspan="1 <br/>
<label id="lbl1" runat="server </label><br/>
<asp:GridView ID="GridView1" runat="server" Height="50px" Width="800px" AutoGenerateColumns="false"<br/>
AllowPaging="true" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="50"<br/>
OnSorting="GridView1_Sorting"<br/>
onselectedindexchanged="GridView1_SelectedIndexChanged <br/>
<Columns>
<br/>
<asp:BoundField DataField="Problem" HeaderText="Problem: " /><br/>
<asp:BoundField DataField="TT" HeaderText="WMS TT#: " /><br/>
<asp:BoundField DataField="Reported" HeaderText="Reported:" /><br/>
<asp:BoundField DataField="ActionsPerformed" HeaderText="ActionsPerformed: " />
<br/>
<asp:TemplateField HeaderText="" ControlStyle-Height="50px" ControlStyle-Width="250px"
ControlStyle-Font-Bold="true" ><br/>
<ItemTemplate><h4 class="style3 Status -
<%# Eval("Status") %></h4></td></tr>
<br/>
</ItemTemplate><br/>
</asp:TemplateField><br/>
<asp:TemplateField HeaderText="" ControlStyle-Height="50px" ControlStyle-Width="250px <br/>
<ItemTemplate> <h4 class="style2 RequiredAction -
<%#Eval("RequiredAction") %> </h4></td></tr><br/>
<tr style="height:40px;width:250px; <td><asp:CheckBox Checked="true" ID="chkbox1" runat="server"
Visible="true" /><br/>
</ItemTemplate>
<br/>
</asp:TemplateField>
<br/>
</Columns><br/>
<RowStyle Height="40px" Width="250px" /><br/>
</asp:GridView><br/>
</td> <br/>
<tr><br/>
<td><br/>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br/>
</td><br/>
</tr><br/>
</table><br/>
</asp:Panel><br/>
</asp:Content><br/>
<asp:Content ID="Content3" runat="server" contentplaceholderid="HeadContent <br/>
<style type="text/css <br/>
.style1<br/>
{<br/>
width: 25px;<br/>
}<br/>
.style2<br/>
{<br/>
font-family:Arial Black;<br/>
font-size:small;<br/>
color:Green;<br/>
background-color:white;<br/>
}<br/>
.style3<br/>
{<br/>
font-weight:bold;<br/>
font-size:small;
<br/>
}<br/>
</style><br/>
</asp:Content><br/>
<br/>
@cs:<br/>
<br/>
using System;<br/>
using System.Collections.Generic;<br/>
using System.Linq;<br/>
using System.Web;<br/>
using System.Web.UI;<br/>
using System.Web.UI.WebControls;<br/>
using MySql.Data.MySqlClient;<br/>
using System.Diagnostics;<br/>
using System.Net;<br/>
using System.Net.Mail;<br/>
using System.IO;<br/>
using System.Text;<br/>
using GridViewClassLibrary;<br/>
<br/>
<br/>
namespace TOR_Tool<br/>
{<br/>
public partial class _Default : System.Web.UI.Page<br/>
{<br/>
protected void Page_Load(object sender, EventArgs e)<br/>
{<br/>
if (!IsPostBack)<br/>
{<br/>
<br/>
}<br/>
<br/>
GridViewHelper helper = new GridViewHelper(GridView1); <br/>
<br/>
helper.RegisterGroup("Problem", true, true);<br/>
helper.RegisterGroup("WMSTT", true, true);<br/>
helper.RegisterGroup("Reported", true, true);<br/>
helper.RegisterGroup("ActionsPerformed", true, true); <br/>
<br/>
helper.GroupHeader += new GroupEvent(helper_GroupHeader);<br/>
<br/>
<br/>
helper.ApplyGroupSort();<br/>
DataUtiliities dt = new DataUtiliities(); <br/>
<br/>
GridView1.DataSource = dt.ExecuteDataSet("select t.Id as TT, t.Subject as Problem, t.Status as Status, u.Name, (tr.Id), tr.Objectid, tr.Type, tr.Creator, (tr.Created),
cast(a.content as char)as ActionsPerformed, (a.Id) as Attachement_Id, (a.TransactionId), a.Creator as Attachment_creator, (a.Created) as Reported, oc.CustomField, oc.ObjectType, oc.ObjectId as ObjectCF_ObjectId, oc.Content as RequiredAction from rt.Tickets
t inner join (select max(id) as id,Objectid,Type,creator,ObjectType,max(created) as created from rt.Transactions where Type in (Create,Correspond) and ObjectType = RT::Ticket group by Objectid order by id desc) tr on tr.Objectid = t.id inner join rt.Attachments
a on a.TransactionId = tr.Id inner join rt.Users u on u.Id = a.Creator inner join rt.ObjectCustomFieldValues oc on oc.ObjectId = tr.ObjectId where t.Status in (pending,open,new) and oc.CustomField in (7) group by t.Id");<br/>
<br/>
GridView1.DataBind();<br/>
<br/>
}<br/>
private void helper_GroupHeader(string groupName, object[] values, GridViewRow row)<br/>
{<br/>
//row.BackColor = Color.AliceBlue;<br/>
row.Cells[0].Font.Bold = true;<br/>
row.Cells[0].Text = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + groupName + " &nbsp;&nbsp; - &nbsp;&nbsp;" + row.Cells[0].Text;<br/>
<br/>
}<br/>
protected void Button1_Click(object sender, EventArgs e)<br/>
{<br/>
// GridView1.Visible = false;<br/>
MailMessage mail = new MailMessage();<br/>
mail.Body= GridViewToHtml(GridView1); <br/>
mail.IsBodyHtml = true;<br/>
mail.Subject = lblHeader.Text + "" + "" + ddlShift.SelectedItem + "" + "" +System.DateTime.Now.ToString();<br/>
mail.To.Add("angel@sat.com");<br/>
mail.From =new MailAddress ("sat01.corp@sat.com");<br/>
SmtpClient smptp = new SmtpClient();<br/>
smptp.Host= "sat01.corp.sat.com"; <br/>
smptp.DeliveryMethod = SmtpDeliveryMethod.Network; <br/>
smptp.Send(mail); <br/>
}<br/>
private string GridViewToHtml(GridView gv)<br/>
{ <br/>
StringBuilder sb = new StringBuilder();<br/>
StringWriter sw = new StringWriter(sb);<br/>
HtmlTextWriter hw = new HtmlTextWriter(sw);<br/>
gv.RenderControl(hw);<br/>
return sb.ToString();<br/>
}<br/>
public override void VerifyRenderingInServerForm(Control control)<br/>
{ <br/>
}<br/>
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)<br/>
{<br/>
GridView1.PageIndex = e.NewPageIndex;<br/>
GridView1.DataBind();<br/>
}<br/>
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)<br/>
{<br/>
}<br/>
<br/>
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)<br/>
{<br/>
}<br/>
}<br/>
}
<br/>

How can i be able to select row or rows from grid view and then display only those selected when its being emailed out?

Thanks!! <hr class="sig rr

View the full article
 
Back
Top