Create Inbox like Gmail Inbox using Gridview in asp.net with c#
Inbox.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/SuccessPlus/Marketing/admin.master" EnableEventValidation="true" AutoEventWireup="true" CodeFile="Inbox.aspx.cs" Inherits="Marketing_Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<input id="hdndranch" runat="server" type="hidden" />
<input id="hdnmanager" runat="server" type="hidden" />
<%-- <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>--%>
<table align="center" class="ad_txt_border" width="700">
<tr>
<td bgcolor="#3399FF" class="ad_head" style="height: 20px" width="20">
<img id="IMG1" src="../images/download_arrow_icon.gif" />Inbox</td>
<td bgcolor="#3399FF" class="ad_head" style="height: 20px">
</td>
</tr>
<tr>
<td bgcolor="" class="ad_head" style="height: 20px" width="20">
<td bgcolor="" class="ad_head" style="height: 20px">
</td>
</tr>
<tr>
<td class="txt" colspan="2">
<%--<asp:Button ID="btnDelete" runat="server"
OnClick="btnDelete_Click"
OnClientClick="return DeleteConfirmation();"
Text="Delete" />--%>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%"
DataKeyNames="Id" BackColor="WhiteSmoke"
onrowdatabound="GridView1_RowDataBound" >
<Columns >
<%--<asp:TemplateField HeaderText="Select">
<HeaderTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
AutoPostBack="True"
oncheckedchanged="CheckBox1_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server"
AutoPostBack="True"
OnCheckedChanged="chkSelect_CheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:Label ID="lblfrom" runat="server" Text='<%# Eval("MailFrom") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:TemplateField HeaderText="" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:Label ID="lblto" runat="server" Text='<%# Eval("MailTo") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Font-Underline="false" runat="server" CommandName='<%# Eval("Id") %>'
Text='<%# Eval("Subject") %>' OnCommand="TabChange"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:Label ID="lblstatus" runat="server" Visible="false" Text='<%# Eval("status") %>'></asp:Label>
<asp:Label ID="lblfname" runat="server" Visible="false" Text='<%# Eval("Filename") %>'></asp:Label>
<asp:Image ID="imgattach" ImageUrl="~/SuccessPlus/images/paperclip.gif" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:HyperLinkField DataNavigateUrlFields="Id" HeaderStyle-BackColor="Gainsboro"
DataNavigateUrlFormatString="~/Employer/DownloadFile.aspx?Id={0}" HeaderText="Download" Text="Download" />--%>
<%-- <asp:TemplateField HeaderText="Download" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:Label ID="lblstatus" runat="server" Visible="false" Text='<%# Eval("status") %>'></asp:Label>
<asp:Label ID="lblfname" runat="server" Visible="false" Text='<%# Eval("Filename") %>'></asp:Label>
<asp:HyperLink ID="lnkDownload" runat="server" NavigateUrl='<%# Eval("Id", "~/SuccessPlus/Marketing/DownloadFile.aspx?Id={0}") %>' Text="Download"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="View" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:HyperLink ID="lnkView" runat="server" NavigateUrl='<%# Eval("Id", "~/SuccessPlus/Marketing/ViewFile.aspx?Id={0}") %>'
Text="View"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:ImageButton ToolTip="Delete" ID="img" runat="server" OnCommand="delete_click" ImageUrl="~/SuccessPlus/images/b_drop.png" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"id") %>'></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>--%>
</Columns>
</asp:GridView>
<%-- <div>
<asp:Table ID="Table1" runat="server" Width="100%" BorderWidth="1">
<asp:TableRow runat="server">
<asp:TableCell runat="server" HorizontalAlign="Center">
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("Id") %>' OnCommand="TabChange"> Tab 1</asp:LinkButton>
</asp:TableCell>
<asp:TableCell runat="server" HorizontalAlign="Center">
<asp:LinkButton ID="LinkButton2" runat="server" OnCommand="TabChange">Tab 2</asp:LinkButton>
</asp:TableCell>
<asp:TableCell ID="TableCell1" runat="server" HorizontalAlign="Center">
<asp:LinkButton ID="LinkButton3" runat="server" OnCommand="TabChange">Tab 3</asp:LinkButton>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>--%>
<asp:MultiView ID="MultiView1" runat="server" Visible="false">
<asp:View ID="View1" runat="server">
<asp:Table ID="Table2" runat="server" BorderWidth="1" Width="100%">
<asp:TableRow>
<asp:TableCell>
<asp:Image ID="Image1" ImageUrl="~/SuccessPlus/images/star_off_sm_2.gif" runat="server" />
<asp:TextBox ID="txtfrom" BorderStyle="None" Width="500px" Text="Renju John <renjujohn.2@gmail.com>"
runat="server"></asp:TextBox>
<asp:TextBox ID="txtdate" BorderStyle="None" Width="500px" Text="Wed, Jul 18, 2012 at 4:28 PM"
runat="server"></asp:TextBox>
<br />
To: <asp:TextBox ID="txtto" BorderStyle="None" Text="suni <sunichand2000@gmail.com>" Width="500px"
runat="server"></asp:TextBox>
<br />
<asp:LinkButton ID="lbreply" runat="server" >Reply</asp:LinkButton>
<asp:LinkButton ID="lbdelete" OnCommand="delete_click" runat="server" >Delete</asp:LinkButton>
<asp:LinkButton ID="lbinbox" OnCommand="inbox_click" runat="server" >Inbox</asp:LinkButton>
<br />
<asp:TextBox ID="txtbody" BorderStyle="None" TextMode="MultiLine" Width="700px" Height="200px"
runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblattach" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:HyperLink ID="hldownload" runat="server" Visible="false">Download</asp:HyperLink>
<asp:HyperLink ID="hlview" runat="server" Visible="false">View</asp:HyperLink>
<br /> <br />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:View>
</asp:MultiView>
</td>
</tr>
</table>
</asp:Content>
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Web.Mail;
using System.IO;
using System.Drawing;
using System.Diagnostics;
public partial class Marketing_Default2 : System.Web.UI.Page
{
Class1 cls = new Class1();
int cid;
connectionClass.connectionClass db = new connectionClass.connectionClass();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
hdndranch.Value = Request.QueryString["branch"].ToString();
hdnmanager.Value = Request.QueryString["manager"].ToString();
gridbind();
}
}
public void gridbind()
{
if (cls.con.State == ConnectionState.Closed)
{
cls.con.Open();
}
SqlDataAdapter da = new SqlDataAdapter("select * from mail where ToType='Marketing Desk'", cls.con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
foreach (GridViewRow row in GridView1.Rows)
{
Label lblstatus = (Label)row.FindControl("lblstatus");
Label lblfname = (Label)row.FindControl("lblfname");
System.Web.UI.WebControls.Image imgattach = (System.Web.UI.WebControls.Image)row.FindControl("imgattach");
//HyperLink lnkDownload = (HyperLink)row.FindControl("lnkDownload");
//HyperLink lnkView = (HyperLink)row.FindControl("lnkView");
if (lblstatus.Text == "False")
{
row.BackColor = System.Drawing.Color.White;
}
else
{
row.BackColor = System.Drawing.Color.Gray;
}
if (lblfname.Text == "")
{
//lnkDownload.Visible = false;
//lnkView.Visible = false;
imgattach.Visible = false;
}
else
{
//lnkDownload.Visible = true;
//lnkView.Visible = true;
imgattach.Visible = true;
}
}
}
protected void TabChange(object sender, CommandEventArgs e)
{
string id = e.CommandName;
SqlDataAdapter da = new SqlDataAdapter("select * from mail where ToType='Marketing Desk' and id='" + id + "'", cls.con);
DataSet ds = new DataSet();
da.Fill(ds);
LinkButton lb = (LinkButton)sender;
if (lb.ID == "LinkButton1")
{
MultiView1.ActiveViewIndex = 0;
MultiView1.Visible = true;
txtfrom.Text = ds.Tables[0].Rows[0]["MailFrom"].ToString();
txtto.Text = ds.Tables[0].Rows[0]["MailTo"].ToString();
txtbody.Text = ds.Tables[0].Rows[0]["MailContent"].ToString();
txtdate.Text = ds.Tables[0].Rows[0]["Date"].ToString();
lbdelete.CommandArgument = id;
if (ds.Tables[0].Rows[0]["Filename"].ToString() != "")
{
lblattach.Text = ds.Tables[0].Rows[0]["Filename"].ToString();
lblattach.Visible = true;
hldownload.Visible = true;
hlview.Visible = true;
hldownload.NavigateUrl = "~/SuccessPlus/Marketing/DownloadFile.aspx?Id="+id+"&branch=" + hdndranch.Value + "&manager=" + hdnmanager.Value;
hlview.NavigateUrl = "~/SuccessPlus/Marketing/DownloadFile.aspx?Id="+id+"&branch=" + hdndranch.Value + "&manager=" + hdnmanager.Value;
}
GridView1.Visible = false;
db.executeNonQuery("update mail set status='1' where id='" + id + "' and ToType='Marketing Desk'", cls.conStr);
db.close();
}
else if (lb.ID == "LinkButton2")
{
MultiView1.ActiveViewIndex = 1;
}
else if (lb.ID == "LinkButton3")
{
MultiView1.ActiveViewIndex = 2;
}
}
public void delete_click(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{
try
{
int id = Convert.ToInt16(e.CommandArgument);
db.executeNonQuery("delete from mail where id='" + id + "' and ToType='Marketing Desk'", cls.conStr);
db.close();
gridbind();
}
catch (Exception ex)
{
}
}
public void inbox_click(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{
try
{
GridView1.Visible = true;
MultiView1.Visible = false;
}
catch (Exception ex)
{
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
////Create String Collection to store IDs of
////records to be deleted .
//StringCollection idCollection = new StringCollection();
//string strID = string.Empty;
////Loop through GridView rows to find checked rows
//for (int i = 0; i < GridView1.Rows.Count; i++)
//{
// CheckBox chkDelete = (CheckBox)GridView1.Rows[i].
// Cells[0].FindControl("chkSelect");
// if (chkDelete != null)
// {
// if (chkDelete.Checked)
// {
// strID = GridView1.Rows[i].Cells[1].Text;
// idCollection.Add(strID);
// }
// }
//}
//if (idCollection.Count > 0)
//{
// //Call the method to Delete records
// DeleteMultipleRecords(idCollection);
// // rebind the GridView
// GridView1.DataBind();
//}
//else
//{
// lblmessage.Text = "Please select any row to delete";
//}
}
// private void DeleteMultipleRecords(StringCollection idCollection)
//{
// //Create sql Connection and Sql Command
//SqlConnection con = new SqlConnection(strConnection);
//SqlCommand cmd = new SqlCommand();
//string IDs = "";
// foreach (string id in idCollection)
// {
// IDs += id.ToString() + ",";
// }
// try
// {
// string test = IDs.Substring
// (0, IDs.LastIndexOf(","));
// string sql = "Delete fromtable"_name +" WHERE uid in (" + test
//+ ")";
// cmd.CommandType = CommandType.Text;
// cmd.CommandText = sql;
// cmd.Connection = con;
// con.Open();
// cmd.ExecuteNonQuery();
// }
// catch (SqlException ex)
// {
// string errorMsg = "Error in Deletion";
// errorMsg += ex.Message;
// throw new Exception(errorMsg);
// }
// finally
// {
// con.Close();
// }
// }
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkTest = (CheckBox)sender;
GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;
grdRow.BackColor = Color.Red;
Label lblfrom = (Label)grdRow.FindControl("lblfrom");
Label lblto = (Label)grdRow.FindControl("lblto");
if (chkTest.Checked)
{
lblfrom.ForeColor = System.Drawing.Color.Black;
lblto.ForeColor = System.Drawing.Color.Black;
}
else
{
grdRow.BackColor = Color.White;
lblfrom.ForeColor = System.Drawing.Color.Blue;
lblto.ForeColor = System.Drawing.Color.Blue;
}
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
foreach (GridViewRow rs in GridView1.Rows)
{
CheckBox chkUncheck = (CheckBox)
rs.FindControl("chkSelect");
if (chkUncheck.Checked)
{ chkUncheck.Checked = false; }
else
{ chkUncheck.Checked = true; }
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Label lblstatus = (Label)e.Row.FindControl("lblstatus");
//if (lblstatus.Text == "False")
//{
// Label lblfrom = (Label)e.Row.FindControl("lblfrom");
// e.Row.BackColor = Color.Gray;
//}
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
}
}
<%@ Page Title="" Language="C#" MasterPageFile="~/SuccessPlus/Marketing/admin.master" EnableEventValidation="true" AutoEventWireup="true" CodeFile="Inbox.aspx.cs" Inherits="Marketing_Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<input id="hdndranch" runat="server" type="hidden" />
<input id="hdnmanager" runat="server" type="hidden" />
<%-- <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>--%>
<table align="center" class="ad_txt_border" width="700">
<tr>
<td bgcolor="#3399FF" class="ad_head" style="height: 20px" width="20">
<img id="IMG1" src="../images/download_arrow_icon.gif" />Inbox</td>
<td bgcolor="#3399FF" class="ad_head" style="height: 20px">
</td>
</tr>
<tr>
<td bgcolor="" class="ad_head" style="height: 20px" width="20">
<td bgcolor="" class="ad_head" style="height: 20px">
</td>
</tr>
<tr>
<td class="txt" colspan="2">
<%--<asp:Button ID="btnDelete" runat="server"
OnClick="btnDelete_Click"
OnClientClick="return DeleteConfirmation();"
Text="Delete" />--%>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%"
DataKeyNames="Id" BackColor="WhiteSmoke"
onrowdatabound="GridView1_RowDataBound" >
<Columns >
<%--<asp:TemplateField HeaderText="Select">
<HeaderTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
AutoPostBack="True"
oncheckedchanged="CheckBox1_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server"
AutoPostBack="True"
OnCheckedChanged="chkSelect_CheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:Label ID="lblfrom" runat="server" Text='<%# Eval("MailFrom") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:TemplateField HeaderText="" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:Label ID="lblto" runat="server" Text='<%# Eval("MailTo") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Font-Underline="false" runat="server" CommandName='<%# Eval("Id") %>'
Text='<%# Eval("Subject") %>' OnCommand="TabChange"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:Label ID="lblstatus" runat="server" Visible="false" Text='<%# Eval("status") %>'></asp:Label>
<asp:Label ID="lblfname" runat="server" Visible="false" Text='<%# Eval("Filename") %>'></asp:Label>
<asp:Image ID="imgattach" ImageUrl="~/SuccessPlus/images/paperclip.gif" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:HyperLinkField DataNavigateUrlFields="Id" HeaderStyle-BackColor="Gainsboro"
DataNavigateUrlFormatString="~/Employer/DownloadFile.aspx?Id={0}" HeaderText="Download" Text="Download" />--%>
<%-- <asp:TemplateField HeaderText="Download" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:Label ID="lblstatus" runat="server" Visible="false" Text='<%# Eval("status") %>'></asp:Label>
<asp:Label ID="lblfname" runat="server" Visible="false" Text='<%# Eval("Filename") %>'></asp:Label>
<asp:HyperLink ID="lnkDownload" runat="server" NavigateUrl='<%# Eval("Id", "~/SuccessPlus/Marketing/DownloadFile.aspx?Id={0}") %>' Text="Download"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="View" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:HyperLink ID="lnkView" runat="server" NavigateUrl='<%# Eval("Id", "~/SuccessPlus/Marketing/ViewFile.aspx?Id={0}") %>'
Text="View"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete" HeaderStyle-BackColor="#3399FF">
<ItemTemplate>
<asp:ImageButton ToolTip="Delete" ID="img" runat="server" OnCommand="delete_click" ImageUrl="~/SuccessPlus/images/b_drop.png" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"id") %>'></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>--%>
</Columns>
</asp:GridView>
<%-- <div>
<asp:Table ID="Table1" runat="server" Width="100%" BorderWidth="1">
<asp:TableRow runat="server">
<asp:TableCell runat="server" HorizontalAlign="Center">
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("Id") %>' OnCommand="TabChange"> Tab 1</asp:LinkButton>
</asp:TableCell>
<asp:TableCell runat="server" HorizontalAlign="Center">
<asp:LinkButton ID="LinkButton2" runat="server" OnCommand="TabChange">Tab 2</asp:LinkButton>
</asp:TableCell>
<asp:TableCell ID="TableCell1" runat="server" HorizontalAlign="Center">
<asp:LinkButton ID="LinkButton3" runat="server" OnCommand="TabChange">Tab 3</asp:LinkButton>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>--%>
<asp:MultiView ID="MultiView1" runat="server" Visible="false">
<asp:View ID="View1" runat="server">
<asp:Table ID="Table2" runat="server" BorderWidth="1" Width="100%">
<asp:TableRow>
<asp:TableCell>
<asp:Image ID="Image1" ImageUrl="~/SuccessPlus/images/star_off_sm_2.gif" runat="server" />
<asp:TextBox ID="txtfrom" BorderStyle="None" Width="500px" Text="Renju John <renjujohn.2@gmail.com>"
runat="server"></asp:TextBox>
<asp:TextBox ID="txtdate" BorderStyle="None" Width="500px" Text="Wed, Jul 18, 2012 at 4:28 PM"
runat="server"></asp:TextBox>
<br />
To: <asp:TextBox ID="txtto" BorderStyle="None" Text="suni <sunichand2000@gmail.com>" Width="500px"
runat="server"></asp:TextBox>
<br />
<asp:LinkButton ID="lbreply" runat="server" >Reply</asp:LinkButton>
<asp:LinkButton ID="lbdelete" OnCommand="delete_click" runat="server" >Delete</asp:LinkButton>
<asp:LinkButton ID="lbinbox" OnCommand="inbox_click" runat="server" >Inbox</asp:LinkButton>
<br />
<asp:TextBox ID="txtbody" BorderStyle="None" TextMode="MultiLine" Width="700px" Height="200px"
runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblattach" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:HyperLink ID="hldownload" runat="server" Visible="false">Download</asp:HyperLink>
<asp:HyperLink ID="hlview" runat="server" Visible="false">View</asp:HyperLink>
<br /> <br />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:View>
</asp:MultiView>
</td>
</tr>
</table>
</asp:Content>
Inbox.aspx.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Web.Mail;
using System.IO;
using System.Drawing;
using System.Diagnostics;
public partial class Marketing_Default2 : System.Web.UI.Page
{
Class1 cls = new Class1();
int cid;
connectionClass.connectionClass db = new connectionClass.connectionClass();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
hdndranch.Value = Request.QueryString["branch"].ToString();
hdnmanager.Value = Request.QueryString["manager"].ToString();
gridbind();
}
}
public void gridbind()
{
if (cls.con.State == ConnectionState.Closed)
{
cls.con.Open();
}
SqlDataAdapter da = new SqlDataAdapter("select * from mail where ToType='Marketing Desk'", cls.con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
foreach (GridViewRow row in GridView1.Rows)
{
Label lblstatus = (Label)row.FindControl("lblstatus");
Label lblfname = (Label)row.FindControl("lblfname");
System.Web.UI.WebControls.Image imgattach = (System.Web.UI.WebControls.Image)row.FindControl("imgattach");
//HyperLink lnkDownload = (HyperLink)row.FindControl("lnkDownload");
//HyperLink lnkView = (HyperLink)row.FindControl("lnkView");
if (lblstatus.Text == "False")
{
row.BackColor = System.Drawing.Color.White;
}
else
{
row.BackColor = System.Drawing.Color.Gray;
}
if (lblfname.Text == "")
{
//lnkDownload.Visible = false;
//lnkView.Visible = false;
imgattach.Visible = false;
}
else
{
//lnkDownload.Visible = true;
//lnkView.Visible = true;
imgattach.Visible = true;
}
}
}
protected void TabChange(object sender, CommandEventArgs e)
{
string id = e.CommandName;
SqlDataAdapter da = new SqlDataAdapter("select * from mail where ToType='Marketing Desk' and id='" + id + "'", cls.con);
DataSet ds = new DataSet();
da.Fill(ds);
LinkButton lb = (LinkButton)sender;
if (lb.ID == "LinkButton1")
{
MultiView1.ActiveViewIndex = 0;
MultiView1.Visible = true;
txtfrom.Text = ds.Tables[0].Rows[0]["MailFrom"].ToString();
txtto.Text = ds.Tables[0].Rows[0]["MailTo"].ToString();
txtbody.Text = ds.Tables[0].Rows[0]["MailContent"].ToString();
txtdate.Text = ds.Tables[0].Rows[0]["Date"].ToString();
lbdelete.CommandArgument = id;
if (ds.Tables[0].Rows[0]["Filename"].ToString() != "")
{
lblattach.Text = ds.Tables[0].Rows[0]["Filename"].ToString();
lblattach.Visible = true;
hldownload.Visible = true;
hlview.Visible = true;
hldownload.NavigateUrl = "~/SuccessPlus/Marketing/DownloadFile.aspx?Id="+id+"&branch=" + hdndranch.Value + "&manager=" + hdnmanager.Value;
hlview.NavigateUrl = "~/SuccessPlus/Marketing/DownloadFile.aspx?Id="+id+"&branch=" + hdndranch.Value + "&manager=" + hdnmanager.Value;
}
GridView1.Visible = false;
db.executeNonQuery("update mail set status='1' where id='" + id + "' and ToType='Marketing Desk'", cls.conStr);
db.close();
}
else if (lb.ID == "LinkButton2")
{
MultiView1.ActiveViewIndex = 1;
}
else if (lb.ID == "LinkButton3")
{
MultiView1.ActiveViewIndex = 2;
}
}
public void delete_click(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{
try
{
int id = Convert.ToInt16(e.CommandArgument);
db.executeNonQuery("delete from mail where id='" + id + "' and ToType='Marketing Desk'", cls.conStr);
db.close();
gridbind();
}
catch (Exception ex)
{
}
}
public void inbox_click(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{
try
{
GridView1.Visible = true;
MultiView1.Visible = false;
}
catch (Exception ex)
{
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
////Create String Collection to store IDs of
////records to be deleted .
//StringCollection idCollection = new StringCollection();
//string strID = string.Empty;
////Loop through GridView rows to find checked rows
//for (int i = 0; i < GridView1.Rows.Count; i++)
//{
// CheckBox chkDelete = (CheckBox)GridView1.Rows[i].
// Cells[0].FindControl("chkSelect");
// if (chkDelete != null)
// {
// if (chkDelete.Checked)
// {
// strID = GridView1.Rows[i].Cells[1].Text;
// idCollection.Add(strID);
// }
// }
//}
//if (idCollection.Count > 0)
//{
// //Call the method to Delete records
// DeleteMultipleRecords(idCollection);
// // rebind the GridView
// GridView1.DataBind();
//}
//else
//{
// lblmessage.Text = "Please select any row to delete";
//}
}
// private void DeleteMultipleRecords(StringCollection idCollection)
//{
// //Create sql Connection and Sql Command
//SqlConnection con = new SqlConnection(strConnection);
//SqlCommand cmd = new SqlCommand();
//string IDs = "";
// foreach (string id in idCollection)
// {
// IDs += id.ToString() + ",";
// }
// try
// {
// string test = IDs.Substring
// (0, IDs.LastIndexOf(","));
// string sql = "Delete fromtable"_name +" WHERE uid in (" + test
//+ ")";
// cmd.CommandType = CommandType.Text;
// cmd.CommandText = sql;
// cmd.Connection = con;
// con.Open();
// cmd.ExecuteNonQuery();
// }
// catch (SqlException ex)
// {
// string errorMsg = "Error in Deletion";
// errorMsg += ex.Message;
// throw new Exception(errorMsg);
// }
// finally
// {
// con.Close();
// }
// }
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkTest = (CheckBox)sender;
GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;
grdRow.BackColor = Color.Red;
Label lblfrom = (Label)grdRow.FindControl("lblfrom");
Label lblto = (Label)grdRow.FindControl("lblto");
if (chkTest.Checked)
{
lblfrom.ForeColor = System.Drawing.Color.Black;
lblto.ForeColor = System.Drawing.Color.Black;
}
else
{
grdRow.BackColor = Color.White;
lblfrom.ForeColor = System.Drawing.Color.Blue;
lblto.ForeColor = System.Drawing.Color.Blue;
}
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
foreach (GridViewRow rs in GridView1.Rows)
{
CheckBox chkUncheck = (CheckBox)
rs.FindControl("chkSelect");
if (chkUncheck.Checked)
{ chkUncheck.Checked = false; }
else
{ chkUncheck.Checked = true; }
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Label lblstatus = (Label)e.Row.FindControl("lblstatus");
//if (lblstatus.Text == "False")
//{
// Label lblfrom = (Label)e.Row.FindControl("lblfrom");
// e.Row.BackColor = Color.Gray;
//}
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
}
}
wow madam dabeli, saras bani............
ReplyDelete