Question : need to select all checkbox in gridview.

    <input id="ctl00_ctl00_cph1_cph1_ctrlMyMail_gvInbox_ctl01_cbSelectAll" type="checkbox" name="ctl00$ctl00$cph1$cph1$ctrlMyMail$gvInbox$ctl01$cbSelectAll" onclick="javascript:SelectAll('ctl00_ctl00_cph1_cph1_ctrlMyMail_gvInbox_ctl01_cbSelectAll');" />
                                           
faiiling on the above.
When I select the checkbox to select all I am not sure why it does not work,.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
<asp:GridView ID="gvInbox" runat="server" DataKeyNames="messageid" OnPageIndexChanging="gvInbox_PageIndexChanging"
                                    OnRowDataBound="gvInbox_RowDataBound" AllowPaging="true" AllowSorting="true"
                                    Width="100%" PageSize="10" AutoGenerateColumns="false" CssClass="customers-grid">
                                    <Columns>
                                        <asp:TemplateField>
                                            <HeaderStyle CssClass="delete-member"></HeaderStyle>
                                            <ItemStyle CssClass="delete-member" Wrap="False" Width="10%"></ItemStyle>
                                            <AlternatingItemTemplate>
                                                <asp:CheckBox ID="cb1" runat="server" />
                                            </AlternatingItemTemplate>
                                            <ItemTemplate>
                                                <asp:CheckBox ID="cb1" runat="server" oncheckedchanged="cb1_CheckedChanged" />
                                            </ItemTemplate>
                                            <HeaderTemplate>
                                                <asp:CheckBox ID="cbSelectAll" runat="server" CausesValidation="True" Text="" OnCheckedChanged="cbSelectAll_CheckedChanged" />
                                            </HeaderTemplate>
                                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" />
                                        </asp:TemplateField>
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace OmegaLove.Web.UI
{
    public partial class ctrlMyMail : OmegaLoveBasePageUserControl
    {
        public static string ConnnectionString = ConfigurationManager.ConnectionStrings["omegaloveConnectionString"].ToString();
        string message = string.Empty;
        DataSet ds = null;
        DataTable dt = null;
        private static string mstrConn = String.Empty;
        private static string UserId = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                UserId = Session["UserName"] == null ? "default if null" : Session["UserName"].ToString();

                if (UserId != null)
                {
                    PopulateMailbox("", "");
                }
                else
                {
                    Response.Redirect("~/Login.aspx");
                }

                // singleton oSingleton = singleton.GetCurrentSingleton();
                // oSingleton.messagesIDList.Clear();

                // SaveCheckedValues();

                // LoadSavedCheckValues();

            }
        }


        private void SetSort(string field, bool asc)
        {
            if (ViewState["SortField"] != null && (string)ViewState["SortField"] == field)
            {
                ViewState["SortAsc"] = !(bool)ViewState["SortAsc"];
            }
            else
            {
                ViewState["SortField"] = field;
                ViewState["SortAsc"] = asc;
            }
        }

       
       

        private void PopulateMailbox(string SortExpression, string DeleteString)
        {
            MembershipUser myObject = Membership.GetUser();
            int intGetProfileID = 0;
            System.Web.Security.MembershipUser mu = System.Web.Security.Membership.GetUser();
            string strUsrId = mu.ProviderUserKey.ToString();
            UserId = Session["UserName"] == null ? "default if null" : Session["UserName"].ToString();
            dt = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, UserId);

            intGetProfileID = Convert.ToInt32(dt.Rows[0]["ProfileID"].ToString());

            try
            {

                ds = DataBase.Procedures.prc_Messages_Select.ToDataSet(ConnnectionString, Convert.ToInt32(dt.Rows[0]["ProfileID"].ToString()), strUsrId, DeleteString);

                if ((ds != null) && (ds.Tables[0] != null) && (ds.Tables[0].Rows.Count > 0))
                {
                    //LABEL_NoMessages.Text = string.Empty;
                    gvInbox.AllowPaging = true;
                    gvInbox.PageSize = 2;
                    //gvInbox.PagerStyle.Mode = PagerMode.NumericPages;
                    // Add filter for inbox, drafts, etc.
                    //gvInbox.DataSource.DefaultView.RowFilter = String.Concat("Station = \'", sStation, "\'");
                    gvInbox.DataSource = ds.Tables[0].DefaultView;
                    gvInbox.Visible = true;
                    gvInbox.DataBind();
                }
                else
                {
                    gvInbox.Visible = false;
                    //LABEL_NoMessages.Text = "No Messages";
                }

                return;
            }
            catch (SqlException e)
            {
                WebMsgBox.Show(e.ToString());
            }
        }

      

        protected void gvInbox_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void gvInbox_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                // Add attribute for onclick event on check box in header passing MessageId of Select All checkbox 
                ((CheckBox)e.Row.FindControl("cbSelectAll")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("cbSelectAll")).ClientID + "')");
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                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/ShowImage.ashx?img_id=" + dtPhotos.Rows[0]["PhotoID"].ToString() + "&" + "imagesize=T" + "&" + "imageisprimary=" + "True" + "'";

                    }

                }
                else
                {

                    // set default image
                }

            }

        }
        protected void cb1_CheckedChanged(object sender, EventArgs e)
        {
            // SaveCheckedValues();
        }

        protected void cbSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            // SaveCheckedValues();
        }

        //protected void BtnDelete_Click(object sender, ImageClickEventArgs e)
        //{
        //    int index = -1;
        //    ImageButton btnDelete = sender as ImageButton;
        //    GridViewRow row = (GridViewRow)btnDelete.NamingContainer;
        //    index = (int)gvInbox.DataKeys[row.RowIndex].Value;
        //    SaveCheckedValues();
        //    PopulateMailbox("", index.ToString());
        //    LoadSavedCheckValues();
        //}


        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;
        }
    }
}

Answer : need to select all checkbox in gridview.

Here is another:

<BODY BGCOLOR="#AAAAFF"
BACKGROUND="../yourdir/image.gif"
TEXT="#000000"
LINK="#0000FF"
VLINK="#FF66FF"
ALINK="#FF0000" > 

Random Solutions  
 
programming4us programming4us