[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

evaluating checkbox in datagrid

Asked by deb_holmes in C# Programming Language, Microsoft Visual C#.Net

Tags: asp.net c# datagrid checkbox

I have a datagrid that uses a templatecolumn to display a bit value from the database as a checkbox.  The datagrid has update functionality and the one field that I want people to be able to change is to toggle this checkbox.  However I can't figure out how to get at the value of the checkbox.   Relevant code is in three parts although I preusme the problem is in the third part, where the update  statement is found.
When I click update on a row in the grow, I get this error:

System.InvalidCastException was unhandled by user code
  Message="Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.CheckBox'."
  Source="Webkinz"
  StackTrace:
       at WebKinz.Charms.gridFound_Update(Object source, DataGridCommandEventArgs e) in C:\All\Visual Studio 2005\Webkinz\Webkinz\Charms.aspx.cs:line 126
       at System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e)
       at System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e)
       at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       at System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e)
       at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
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:
In the ASPX page, inside the datagrid
<asp:TemplateColumn HeaderText="Have?" SortExpression="found">
                    <ItemTemplate>
                      <asp:CheckBox runat="server" id="chkFound" 
                             Checked='<%#DataBinder.Eval(Container.DataItem,"found") %>'/>
                    </ItemTemplate>
                </asp:TemplateColumn>
 
Code for loading the datagrid. This works fine to properly populate the checkboxes in every row
protected void loadGrids(string account,string sort)
        {
            SqlConnection conn = new SqlConnection(c.getConnectionString());
            conn.Open();
            string queryString = "exec webkinz_charm_forest_all '" + account + "'";
            SqlDataAdapter adpt = new SqlDataAdapter(queryString, conn);
            DataSet ds = new DataSet();
            adpt.Fill(ds);
            gridFound.DataSource = ds;
            gridFound.DataBind();            
            gridFound.VirtualItemCount = 40;
            conn.Close();
        }
 
Also in the .cs file, the udpate statment:
 
        protected void gridFound_Update(object source, DataGridCommandEventArgs e)
        {
            bool b = ((CheckBox)e.Item.Cells[8].Controls[0]).Checked;
            if (b)
            {
                Label1.Text = "TRUE";
            }
            else
            {
                Label1.Text = "FALSE";
            }
{
[+][-]04/18/09 07:14 PM, ID: 24177666Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04/18/09 07:15 PM, ID: 24177669Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C# Programming Language, Microsoft Visual C#.Net
Tags: asp.net c# datagrid checkbox
Sign Up Now!
Solution Provided By: wht1986
Participating Experts: 2
Solution Grade: A
 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625