Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I have an error with a checkbox.

Posted on 2010-09-06
14
Medium Priority
?
430 Views
Last Modified: 2012-05-10

Server Error in / Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:



using System;
using System.Data.SqlClient;
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.Xml.Linq;
using OmegaLove.DatePicker;
using OmegaLove.BLL;
using System.Globalization;
using Resources;
using System.Web.Profile;
using System.Net;
using System.Threading;
using DataTransfer.Tables;
using System.Collections.Specialized;
using System.Text;
using System.ComponentModel;
using System.Configuration;
using System.Data;



namespace OmegaLove.Web.UI
{
    public partial class ctrlInbox : OmegaLoveBasePageUserControl
    {
      


        public static string ConnnectionString = ConfigurationManager.ConnectionStrings["omegaloveConnectionString"].ToString();
        string message = string.Empty;
        private static DataSet ds = null;
        private static DataTable dt = null;
        private static string mstrConn = String.Empty;
        private static string UserId = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(HttpContext.Current.User.Identity.IsAuthenticated))
                Response.Redirect("~/Login.aspx");
            UserId = HttpContext.Current.User.Identity.Name;
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            if (!IsPostBack)
            {
             
                IsSentItems = Request.QueryString["sent"] != null;
                BindData();


            }
            
        }


        private void BindData()
        {
            string constr = ConnnectionString;
            int intGetProfileID = 0;
            if (UserId == null)
                UserId = HttpContext.Current.User.Identity.Name;


            dt = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, UserId);
            intGetProfileID = Convert.ToInt32(dt.Rows[0]["ProfileID"].ToString());


            int toUserID = 0;
            int fromUserID = 0;
            if (IsSentItems)
                fromUserID = intGetProfileID;
            else
                toUserID = intGetProfileID;
            tbl_PMessage tbl_PMessage = new tbl_PMessage();
            //ds = DataBase.Procedures.prc_Messages_Select_All.ToDataSet(ConnnectionString, Convert.ToInt32(dt.Rows[0]["ProfileID"].ToString()));
            using (DataView dv = DB.pmessage_list(toUserID,fromUserID,null).DefaultView) 
            {
               
                Inbox.DataSource = dv;
                DataBind();
            }


        }
        private void GetData()
        {
            ArrayList arr;
            if (ViewState["SelectedRecords"] != null)
                arr = (ArrayList)ViewState["SelectedRecords"];
            else
                arr = new ArrayList();
            if (Inbox.Rows.Count > 0)
            {
                CheckBox chkAll = (CheckBox)Inbox.HeaderRow.Cells[0].FindControl("chkAll");
                for (int i = 0; i < Inbox.Rows.Count; i++)
                {
                    if (chkAll.Checked)
                    {
                        if (!arr.Contains(Inbox.DataKeys[i].Value))
                        {
                            arr.Add(Inbox.DataKeys[i].Value);
                        }
                    }
                    else
                    {
                        CheckBox chk = (CheckBox)Inbox.Rows[i].Cells[0].FindControl("chk");
                        if (chk.Checked)
                        {
                            if (!arr.Contains(Inbox.DataKeys[i].Value))
                            {
                                arr.Add(Inbox.DataKeys[i].Value);
                            }
                        }
                        else
                        {
                            if (arr.Contains(Inbox.DataKeys[i].Value))
                            {
                                arr.Remove(Inbox.DataKeys[i].Value);
                            }
                        }
                    }
                }

            }
            ViewState["SelectedRecords"] = arr;
        }


        private void DeleteRecord(string pmessageid)
        {
            string constr = ConfigurationManager.ConnectionStrings["omegaloveConnectionString"].ToString();
            string query = "delete from tbl_PMessage" + "where PMessageID=@pmessageid";
            SqlConnection con = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand(query, con);
            cmd.Parameters.AddWithValue("@pmessageid", pmessageid);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }


        protected void OnPaging(object sender, GridViewPageEventArgs e)
        {
            Inbox.PageIndex = e.NewPageIndex;
            Inbox.DataBind();
            SetData();
        }

        private void SetData()
        {
            int currentCount = 0;
            CheckBox chkAll = (CheckBox)Inbox.HeaderRow.Cells[0].FindControl("chkAll");
            chkAll.Checked = true;
            ArrayList arr = (ArrayList)ViewState["SelectedRecords"];
            for (int i = 0; i < Inbox.Rows.Count; i++)
            {
                CheckBox chk = (CheckBox)Inbox.Rows[i].Cells[0].FindControl("chk");
                if (chk != null)
                {
                    chk.Checked = arr.Contains(Inbox.DataKeys[i].Value);
                    if (!chk.Checked)
                        chkAll.Checked = false;
                    else
                        currentCount++;
                }
            }
            hfCount.Value = (arr.Count - currentCount).ToString();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int count = 0;
            SetData();
            Inbox.AllowPaging = false;
            Inbox.DataBind();

            ArrayList arr = (ArrayList)ViewState["SelectedRecords"];
            count = arr.Count;
            for (int i = 0; i < Inbox.Rows.Count; i++)
            {
                if (arr.Contains(Inbox.DataKeys[i].Value))
                {
                    DeleteRecord(Inbox.DataKeys[i].Value.ToString());
                    arr.Remove(Inbox.DataKeys[i].Value);
                }
            }
            ViewState["SelectedRecords"] = arr;
            hfCount.Value = "0";
            Inbox.AllowPaging = true;
            DataBind();
            ShowMessage(count);

        }



        protected string DisplayDiscontinuedAsYESorNO(bool discontinued)
        {
            if (discontinued)
                return "YES";
            else
                return "NO";
        }

      

        protected bool IsSentItems
        {
            get
            {
                return (bool)ViewState["IsSentItems"];
            }
            set
            {
                ViewState["IsSentItems"] = value;
            }
        }

        private void ShowMessage(int count)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script type = 'text/javascript'>");
            sb.Append("alert('");
            sb.Append(count.ToString());
            sb.Append(" records deleted.');");
            sb.Append("</script>");
            Page.ClientScript.RegisterStartupScript(this.GetType(),
                            "script", sb.ToString());
        }

        protected void Inbox_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            Inbox.PageIndex = e.NewPageIndex;
            BindData();
        }

        protected void Inbox_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#CADDFD';");
                if (e.Row.RowIndex % 2 == 0)
                { // even
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF';");
                } // odd
                else
                {
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#D5E5FC';");
                }

                HiddenField hdimageId = (HiddenField)e.Row.FindControl("hiddenImgID");

                System.Web.UI.WebControls.Image MainPicID = (System.Web.UI.WebControls.Image)(e.Row.FindControl("MainPicID"));

                MainPicID.ID = hdimageId.Value;
                MainPicID.ToolTip = "Thumbnail of Photo Number =" + hdimageId.Value;


                DataTable dtPhotos = new DataTable();
                dtPhotos = DataBase.Procedures.prc_Photos_Select_Primary.ToDataTable(ConnnectionString, Convert.ToInt32(hdimageId.Value));

                // Get img id from datatable.
                if (((dtPhotos != null) && (dtPhotos.Rows.Count > 0)))
                {
                    if (Convert.ToBoolean(dtPhotos.Rows[0]["p_Primary"]))
                    {
                        MainPicID.ImageUrl = "~/Secure/ShowThumbnail.ashx?img_id=" + dtPhotos.Rows[0]["PhotoID"].ToString() + "&" + "imagesize=T" + "&" + "imageisprimary=" + "True" + "'";
                    }

                }
                else
                {

                    // set default image
                }

            }

        }

        public static string GetConnectionString(string _connectionStringsName)
        {
            System.Configuration.ConnectionStringSettingsCollection config = System.Configuration.ConfigurationManager.ConnectionStrings;
            for (int i = 0; i < config.Count; i++)
            {
                if (config[i].Name.Equals(_connectionStringsName, StringComparison.OrdinalIgnoreCase))
                    return config[i].ToString();
            }
            return String.Empty;
        }

        
    }
}

Open in new window

Line 161:                if (chk != null)
Line 162:                {
Line 163:                    chk.Checked = arr.Contains(Inbox.DataKeys[i].Value);
Line 164:                    if (!chk.Checked)
Line 165:                        chkAll.Checked = false;
 
</code>

Open in new window

0
Comment
Question by:omegalove
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 7

Expert Comment

by:Inteqam
ID: 33614818
Inbox.DataKeys[i]

are you sure that Inbox.DataKeys is not null?
0
 

Author Comment

by:omegalove
ID: 33614851
I am thing something is happenning weird.
May be take a look at the ui.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ctrlInbox.ascx.cs" Inherits="OmegaLove.Web.UI.ctrlInbox" %>
<%@ Register Assembly="System.Web.Ajax" Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<script type="text/javascript">
<!--
    function Check_Click(objRef) {
        //Get the Row based on checkbox
        var row = objRef.parentNode.parentNode;

        //Get the reference of GridView
        var GridView = row.parentNode;

        //Get all input elements in Gridview
        var inputList = GridView.getElementsByTagName("input");

        for (var i = 0; i < inputList.length; i++) {
            //The First element is the Header Checkbox
            var headerCheckBox = inputList[0];

            //Based on all or none checkboxes
            //are checked check/uncheck Header Checkbox
            var checked = true;
            if (inputList[i].type == "checkbox" && inputList[i] != headerCheckBox) {
                if (!inputList[i].checked) {
                    checked = false;
                    break;
                }
            }
        }
        headerCheckBox.checked = checked;

    }
    function checkAll(objRef) {
        var GridView = objRef.parentNode.parentNode.parentNode;
        var inputList = GridView.getElementsByTagName("input");
        for (var i = 0; i < inputList.length; i++) {
            var row = inputList[i].parentNode.parentNode;
            if (inputList[i].type == "checkbox" && objRef != inputList[i]) {
                if (objRef.checked) {
                    inputList[i].checked = true;
                }
                else {
                    if (row.rowIndex % 2 == 0) {
                        row.style.backgroundColor = "#C2D69B";
                    }
                    else {
                        row.style.backgroundColor = "white";
                    }
                    inputList[i].checked = false;
                }
            }
        }
    }
//-->
</script>
<script type="text/javascript">
    function ConfirmDelete() {
        var count = document.getElementById("<%=hfCount.ClientID %>").value;
        var gv = document.getElementById("<%=Inbox.ClientID%>");
        var chk = gv.getElementsByTagName("input");
        for (var i = 0; i < chk.length; i++) {
            if (chk[i].checked && chk[i].id.indexOf("chkAll") == -1) {
                count++;
            }
        }
        if (count == 0) {
            alert("No records to delete.");
            return false;
        }
        else {
            return confirm("Do you want to delete " + count + " records.");
        }
    }
</script>


<table cellpadding="0" cellspacing="0" class="mbx">
    <tr>
        <td colspan="10" class="ctrl">
            <div class="fold">
                Inbox</div>
        </td>
    </tr>
</table>
<asp:GridView ID="Inbox" runat="server" DataKeyNames="pmessageid" GridLines="None"
    OnPageIndexChanging="OnPaging" OnRowDataBound="Inbox_RowDataBound" Height="20px"
    HorizontalAlign="Center" VerticalAlign="Middle" AllowPaging="true" AllowSorting="true"
    EmptyDataText="No data available." PageSize="5" AutoGenerateColumns="false" CssClass="customers-grid">
    <AlternatingRowStyle Height="25px" HorizontalAlign="Center" BackColor="#D5E5FC" VerticalAlign="Middle" />
    <Columns>
        <asp:TemplateField HeaderText="Delete">
            <HeaderStyle CssClass="delete-member"></HeaderStyle>
            <ItemStyle CssClass="delete-member" Wrap="False"></ItemStyle>
            <HeaderTemplate>
                <asp:CheckBox ID="chkAll" runat="server" onclick="checkAll(this);" />
            </HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="chk" runat="server" onclick="Check_Click(this)" />
            </ItemTemplate>
        </asp:TemplateField>


        <asp:TemplateField HeaderText="From">
            <HeaderStyle CssClass="from-pic"></HeaderStyle>
            <ItemStyle CssClass="from-pic" Wrap="False"></ItemStyle>
            <ItemTemplate>
                <br />
                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#"~/Secure/ShowMessage.aspx?FromProfileID="+Eval("FromProfileID")+"&PMessageID="+Eval("PMessageId")  + "&FromUsername=" + Eval("FromUser")  %>'>
                    <asp:Image ID="MainPicID" BorderWidth="2" BorderColor="Silver" Style="vertical-align: middle"
                        class="srpic" runat="server" />
                </asp:HyperLink><br />
                <%#DataBinder.Eval(Container, "DataItem.FromUser")%>
                <asp:HiddenField ID="hiddenImgID" runat="server" Value='<%#DataBinder.Eval(Container,"DataItem.FromProfileID") %>' />
            </ItemTemplate>
        </asp:TemplateField>


        <asp:TemplateField HeaderText="Subject" HeaderStyle-CssClass="subject" ItemStyle-CssClass="subject">
            <HeaderStyle CssClass="subject" />
            <ItemStyle CssClass="subject" />
            <ItemTemplate>
                <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%#"~/Secure/ShowMessage.aspx?FromProfileID="+Eval("FromProfileID")+"&MessageID="+Eval("PMessageId") + "&FromUsername=" + Eval("FromUser") %>'>
                <%# Convert.ToBoolean(DataBinder.Eval(Container, "DataItem.IsRead")) ? "" : "<img src=\"../../Images/Icons/mail-new.gif\" align=\"bottom\" hspace=\"5\" border=\"0\">"%><%# DataBinder.Eval(Container, "DataItem.Subject") %>
                </asp:HyperLink>
            </ItemTemplate>
        </asp:TemplateField>


        <asp:TemplateField HeaderText="Message" HeaderStyle-CssClass="body" ItemStyle-CssClass="body">
            <HeaderStyle CssClass="body" />
            <ItemStyle CssClass="body" />
            <ItemTemplate>
                <div style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 200px;">
                    <label>
                        <%#DataBinder.Eval(Container, "DataItem.Body")%>
                    </label>
                </div>
            </ItemTemplate>
        </asp:TemplateField>


        <asp:TemplateField HeaderText="Date" HeaderStyle-CssClass="date-sent" ItemStyle-CssClass="date-sent">
            <HeaderStyle CssClass="date-sent" />
            <ItemStyle CssClass="date-sent" />
            <ItemTemplate>
                <%# String.Format("{0:MMM-dd-yyyy HH:mm:ss tt}", ((System.Data.DataRowView)Container.DataItem)["Created"])%>
            </ItemTemplate>
        </asp:TemplateField>


        <asp:TemplateField HeaderText="Read" HeaderStyle-CssClass="read" ItemStyle-CssClass="read">
            <HeaderStyle CssClass="read" />
            <ItemStyle CssClass="read" />
            <ItemTemplate>
                <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl='<%#"~/Secure/ShowMessage.aspx?FromProfileID="+Eval("FromProfileID")+"&MessageID="+Eval("PMessageId")  + "&FromUsername=" + Eval("FromUser")  %>'>
                <%# DisplayDiscontinuedAsYESorNO(Convert.ToBoolean(Eval("IsRead")))%>
                </asp:HyperLink>
                <%-- <asp:Label runat="server" ID="UserPMessageID" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem,"UserPMessageID") %>' />--%>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<asp:HiddenField ID="hfCount" runat="server" Value="0" />
<asp:Button ID="btnDelete" runat="server" Text="Delete Checked Records" OnClientClick="return ConfirmDelete();"
    OnClick="btnDelete_Click" />
<br />
(* Note: Message(s) will be automatically deleted after 30 days from the received
date)
<br />

Open in new window

0
 
LVL 7

Expert Comment

by:Inteqam
ID: 33614988
at what line does the error happen? and when? when clicking delete or when paging?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:omegalove
ID: 33615001
when clicking the delete
0
 

Author Comment

by:omegalove
ID: 33615047
goto omegalove.com

login with user: mathew
                pass: mathew
and goto the mailbox
and try to delete a message.
0
 

Author Comment

by:omegalove
ID: 33615429
it is working now. But it does not delete the record.

I am not sure if it is the update panel or what?
using System;
using System.Data.SqlClient;
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.Xml.Linq;
using OmegaLove.DatePicker;
using OmegaLove.BLL;
using System.Globalization;
using Resources;
using System.Web.Profile;
using System.Net;
using System.Threading;
using DataTransfer.Tables;
using System.Collections.Specialized;
using System.Text;
using System.ComponentModel;
using System.Configuration;
using System.Data;



namespace OmegaLove.Web.UI
{
    public partial class ctrlInbox : OmegaLoveBasePageUserControl
    {



        public static string ConnnectionString = ConfigurationManager.ConnectionStrings["omegaloveConnectionString"].ToString();
        string message = string.Empty;
        private static DataSet ds = null;
        private static DataTable dt = null;
        private static string mstrConn = String.Empty;
        private static string UserId = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(HttpContext.Current.User.Identity.IsAuthenticated))
                Response.Redirect("~/Login.aspx");
            UserId = HttpContext.Current.User.Identity.Name;
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            if (IsPostBack)
            {
                GetData();
            }
            else
             IsSentItems = Request.QueryString["sent"] != null;
            BindGrid();

        }


        private void BindGrid()
        {
            string constr = ConnnectionString;
            int intGetProfileID = 0;
            if (UserId == null)
                UserId = HttpContext.Current.User.Identity.Name;


            dt = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, UserId);
            intGetProfileID = Convert.ToInt32(dt.Rows[0]["ProfileID"].ToString());


            int toUserID = 0;
            int fromUserID = 0;
            if (IsSentItems)
                fromUserID = intGetProfileID;
            else
                toUserID = intGetProfileID;
            tbl_PMessage tbl_PMessage = new tbl_PMessage();
            //ds = DataBase.Procedures.prc_Messages_Select_All.ToDataSet(ConnnectionString, Convert.ToInt32(dt.Rows[0]["ProfileID"].ToString()));
            using (DataView dv = DB.pmessage_list(toUserID, fromUserID, null).DefaultView)
            {

                Inbox.DataSource = dv;
                Inbox.DataBind();
            }
            //DataTable dtMessage = new DataTable();

            //dtMessage = DB.pmessage_list(toUserID, fromUserID, null);
            //Inbox.DataSource = dtMessage;
            //Inbox.DataBind();

        }


        private void GetData()
        {
            ArrayList arr;
            if (ViewState["SelectedRecords"] != null)
                arr = (ArrayList)ViewState["SelectedRecords"];
            else
                arr = new ArrayList();
            if (Inbox.Rows.Count > 0)
            {
                CheckBox chkAll = (CheckBox)Inbox.HeaderRow.Cells[0].FindControl("chkAll");
                for (int i = 0; i < Inbox.Rows.Count; i++)
                {
                    if (chkAll.Checked)
                    {
                        if (!arr.Contains(Inbox.DataKeys[i].Value))
                        {
                            arr.Add(Inbox.DataKeys[i].Value);
                        }
                    }
                    else
                    {
                        CheckBox chk = (CheckBox)Inbox.Rows[i].Cells[0].FindControl("chk");
                        if (chk.Checked)
                        {
                            if (!arr.Contains(Inbox.DataKeys[i].Value))
                            {
                                arr.Add(Inbox.DataKeys[i].Value);
                            }
                        }
                        else
                        {
                            if (arr.Contains(Inbox.DataKeys[i].Value))
                            {
                                arr.Remove(Inbox.DataKeys[i].Value);
                            }
                        }
                    }
                }

            }
            ViewState["SelectedRecords"] = arr;
        }



        private void DeleteRecord(string pmessageid)
        {
            string constr = ConfigurationManager.ConnectionStrings["omegaloveConnectionString"].ToString();
            string query = "delete from tbl_PMessage" + "where PMessageID=@pmessageid";
            SqlConnection con = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand(query, con);
            cmd.Parameters.AddWithValue("@pmessageid", pmessageid);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }


        protected void OnPaging(object sender, GridViewPageEventArgs e)
        {
            Inbox.PageIndex = e.NewPageIndex;
            Inbox.DataBind();
            SetData();
        }

        private void SetData()
        {
            int currentCount = 0;
            CheckBox chkAll = (CheckBox)Inbox.HeaderRow.Cells[0].FindControl("chkAll");
            chkAll.Checked = true;
            ArrayList arr = (ArrayList)ViewState["SelectedRecords"];
            for (int i = 0; i < Inbox.Rows.Count; i++)
            {
                CheckBox chk = (CheckBox)Inbox.Rows[i].Cells[0].FindControl("chk");
                if (chk != null)
                {
                    chk.Checked = arr.Contains(Inbox.DataKeys[i].Value);
                    if (!chk.Checked)
                        chkAll.Checked = false;
                    else
                        currentCount++;
                }
            }
            hfCount.Value = (arr.Count - currentCount).ToString();
        }


        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int count = 0;
            SetData();
            Inbox.AllowPaging = false;
            Inbox.DataBind();

            ArrayList arr = (ArrayList)ViewState["SelectedRecords"];
            count = arr.Count;
            for (int i = 0; i < Inbox.Rows.Count; i++)
            {
                if (arr.Contains(Inbox.DataKeys[i].Value))
                {
                    DeleteRecord(Inbox.DataKeys[i].Value.ToString());
                    arr.Remove(Inbox.DataKeys[i].Value);
                }
            }
            ViewState["SelectedRecords"] = arr;
            hfCount.Value = "0";
            Inbox.AllowPaging = true;
            BindGrid();
            ShowMessage(count);

        }



        protected string DisplayDiscontinuedAsYESorNO(bool discontinued)
        {
            if (discontinued)
                return "YES";
            else
                return "NO";
        }

     


        protected bool IsSentItems
        {
            get
            {
                return (bool)ViewState["IsSentItems"];
            }
            set
            {
                ViewState["IsSentItems"] = value;
            }
        }

        private void ShowMessage(int count)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script type = 'text/javascript'>");
            sb.Append("alert('");
            sb.Append(count.ToString());
            sb.Append(" records deleted.');");
            sb.Append("</script>");
            Page.ClientScript.RegisterStartupScript(this.GetType(),
                            "script", sb.ToString());
        }

        protected void Inbox_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            Inbox.PageIndex = e.NewPageIndex;
            BindGrid();
        }

        protected void Inbox_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#CADDFD';");
                if (e.Row.RowIndex % 2 == 0)
                { // even
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF';");
                } // odd
                else
                {
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#D5E5FC';");
                }

                HiddenField hdimageId = (HiddenField)e.Row.FindControl("hiddenImgID");

                System.Web.UI.WebControls.Image MainPicID = (System.Web.UI.WebControls.Image)(e.Row.FindControl("MainPicID"));

                MainPicID.ID = hdimageId.Value;
                MainPicID.ToolTip = "Thumbnail of Photo Number =" + hdimageId.Value;


                DataTable dtPhotos = new DataTable();
                dtPhotos = DataBase.Procedures.prc_Photos_Select_Primary.ToDataTable(ConnnectionString, Convert.ToInt32(hdimageId.Value));

                // Get img id from datatable.
                if (((dtPhotos != null) && (dtPhotos.Rows.Count > 0)))
                {
                    if (Convert.ToBoolean(dtPhotos.Rows[0]["p_Primary"]))
                    {
                        MainPicID.ImageUrl = "~/Secure/ShowThumbnail.ashx?img_id=" + dtPhotos.Rows[0]["PhotoID"].ToString() + "&" + "imagesize=T" + "&" + "imageisprimary=" + "True" + "'";
                    }

                }
                else
                {

                    // set default image
                }

            }

        }

        public static string GetConnectionString(string _connectionStringsName)
        {
            System.Configuration.ConnectionStringSettingsCollection config = System.Configuration.ConfigurationManager.ConnectionStrings;
            for (int i = 0; i < config.Count; i++)
            {
                if (config[i].Name.Equals(_connectionStringsName, StringComparison.OrdinalIgnoreCase))
                    return config[i].ToString();
            }
            return String.Empty;
        }


    }
}
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/TwoColumn.master" AutoEventWireup="true"
    CodeBehind="MailBox.aspx.cs" Inherits="OmegaLove.Web.UI.Pages.MailBox" %>

<%@ Register Assembly="System.Web.Ajax" Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cph1" runat="server">
    <div id="bodyBlock">
        <div id="AccountPage" class="CommonPage">
            <table cellpadding="2" cellspacing="0">
                <tr>
                    <td class="cntbx">
                        <h1>
                            Mailbox</h1>
                        <p class="desc">
                            Check or manage all your read, unread or sent messages. Please note that messages
                            older than 30 days will be automatically deleted.
                        </p>
                        <div class="inbox">
                            <table cellpadding="5" cellspacing="0" class="head">
                                <tr>
                                    <td class="l">
                                        Folders:
                                    </td>
                                    <td class="r">
                                        <b><a href='https://secure.promatching.com/myaccount.aspx?tab=mailbox&mode=inbox'>Inbox</a></b>&nbsp;&nbsp;-&nbsp;&nbsp;<a
                                            href='https://secure.promatching.com/myaccount.aspx?tab=mailbox&mode=outbox'>Sent
                                            Items</a>
                                    </td>
                                </tr>
                            </table>
                            <table cellpadding="0" cellspacing="0" class="vitbl">
                                <tr>
                                    <td>
                                        <div style="float: right; padding-top: 1px;">
                                            (1/50)</div>
                                        <div class="usage">
                                            <div class="used" style="width: 2px">
                                                <em>2%</em></div>
                                        </div>
                                        <div style="float: right; padding-top: 1px;">
                                            Inbox Usage:</div>
                                    </td>
                                </tr>
                            </table>
                            <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" runat="server">
                                <ContentTemplate>
                                    <OmegaLove:ctrlInbox ID="ctrlInbox" runat="server" />
                                </ContentTemplate>
                            </asp:UpdatePanel>
                            <%--<table cellpadding="0" cellspacing="0" class="mbx" style="margin-top: 0;">
                                <tr>
                                    <th class="status" style="text-align: center">
                                        ?
                                    </th>
                                    <th class="cbox" style="text-align: center">
                                        <input id="ctl00_CPH1_ctl00_LVMessages_ctl01" type="checkbox" name="ctl00$CPH1$ctl00$LVMessages$ctl01"
                                            onclick="ToggleItems(this);" />
                                    </th>
                                    <th class="sender">
                                        From
                                    </th>
                                    <th class="titile">
                                        Title
                                    </th>
                                    <th class="date">
                                        Date
                                    </th>
                                </tr>
                                <tr>
                                    <td>
                                        <img src='https://secure.promatching.com/css/img/icon/16/mail-reply.gif' alt="" />
                                    </td>
                                    <td>
                                        <input id="ctl00_CPH1_ctl00_LVMessages_ctrl0_CBInboxItem" type="checkbox" name="ctl00$CPH1$ctl00$LVMessages$ctrl0$CBInboxItem" />
                                    </td>   
                                    <td class="sender" style="cursor: pointer" onclick='ShowMessage(8578)'>
                                        oliviababy
                                    </td>
                                    <td style="cursor: pointer" onclick='ShowMessage(8578)'>
                                        Hello Dear,
                                    </td>
                                    <td style="cursor: pointer" onclick='ShowMessage(8578)'>
                                        Aug-25-2010 10:36 AM
                                    </td>
                                </tr>
                            </table>--%>
                            <table cellpadding="5" cellspacing="0" class="legend">
                                <tr>
                                    <td style="width: 1%; white-space: nowrap; color: #678">
                                        Indicators:
                                    </td>
                                    <td>
                                        <div style="float: right">
                                            <span class="read">Read</span> <span class="new">Unread</span> <span class="reply">Replied</span><span
                                                class="delete">Deleted without reading</span></div>
                                    </td>
                                </tr>
                            </table>
                            <div style="margin-top: 15px; color: #696763; font-size: 8pt; float: left;">
                                <b style="margin-left: 5px">Note: </b><span>Messages older than 30 days will be automatically
                                    deleted.</span>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</asp:Content>

Open in new window

0
 
LVL 7

Expert Comment

by:Inteqam
ID: 33615472
are you using Ajax?!
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 33615484
can you do debugging to see what is null?

if not, try to log:
chk.Checked
arr.length
Inbox.DataKeys[i]
Inbox.DataKeys[i].Value

and see which one causes the problem
0
 

Author Comment

by:omegalove
ID: 33618119
How should I update the page if it is in the grid is in a control?
0
 

Author Comment

by:omegalove
ID: 33619384
hi I am not getting null any more just a problem deleting a refresh
0
 

Author Comment

by:omegalove
ID: 33622088
Line: 976
Error: Sys.WebForms.PageRequestManagerServerErrorException: The DELETE statement conflicted with the REFERENCE constraint "FK_tbl_UserPMessage_tbl_PMessage". The conflict occurred in database "omegalove", table "dbo.tbl_UserPMessage", column 'PMessageID'.
The statement has been terminated.
what should I do?
0
 
LVL 7

Accepted Solution

by:
Inteqam earned 2000 total points
ID: 33622697
aha

so, you are trying to delete a record while there are other records in other tables linked to it!!

delete related records from PMessage before deleting from UserPMessage.

ask your DBAdmin abouit that constraint.
0
 

Author Closing Comment

by:omegalove
ID: 33623123
l
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 33623135
glad i helped/
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 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