?
Solved

Checkbox control for Datagrid in ASP .NET

Posted on 2005-03-06
7
Medium Priority
?
551 Views
Last Modified: 2008-02-01
i'm trying to get the control of the checkbox i had placed in a datagrid.
but for some reasons, the control does not seems to work.
i tried printing out the checked value, and i get all false even if i checked on the datagrid.

did i miss out on something, like setting the properties of the datagrid?

my codes are as follows:
--------------------------------------------------------------------------------------------------

        Dim GridItem As DataGridItem
        Dim chkExport As System.Web.UI.WebControls.CheckBox
        Dim oExArgs As New System.Collections.ArrayList
        Dim sID As String

        For Each GridItem In DataGrid1.Items
            chkExport = GridItem.FindControl("b")
            Response.Write(chkExport.Checked)

            If chkExport.Checked = False Then
                sID = CType(GridItem.FindControl("a"), Label).Text
                oExArgs.Add(sID)
            End If
        Next

-------------------------------------------------------------------------------------------------
0
Comment
Question by:jericho_law
[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
  • 5
  • 2
7 Comments
 

Author Comment

by:jericho_law
ID: 13469692
Need URGENT help on this.

Please Help.
Thanks.
0
 
LVL 10

Expert Comment

by:NetDeveloper
ID: 13469950
Hi jericho, u must cast the control to CheckBox - as u did later for the Label 'a'

 For Each GridItem In DataGrid1.Items

           ' do the cast to CheckBox
            chkExport = CType(GridItem.FindControl("b"),CheckBox)
            Response.Write(chkExport.Checked)

            If chkExport.Checked = False Then
                sID = CType(GridItem.FindControl("a"), Label).Text
                oExArgs.Add(sID)
            End If
        Next
0
 

Author Comment

by:jericho_law
ID: 13470008
i tried adding the casting you mentioned.
it returned me a error stating that Checkbox is a type and cannot be used as an expression.

i tried using the codes i posted in my previous project and it work perfectly fine.
but now i'm having problems with the same exact coding.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:jericho_law
ID: 13470012
no more errors now, but it still doesn't work.
i get all false even if i checked on the checkbox.
prior to what i mentioned earlier, the codes work well in my previous project.
i'm thinking what could be the problem as it seems like it can't be able to get the status of the checkbox.

----------------------------------------------------------------------------------------------------------------

For Each GridItem In DataGrid1.Items
            chkExport = CType(GridItem.FindControl("b"), CheckBox)
            Response.Write(chkExport.Checked)

            If chkExport.Checked = False Then
                sID = CType(GridItem.FindControl("a"), Label).Text
                oExArgs.Add(sID)
            End If
Next
0
 
LVL 10

Accepted Solution

by:
NetDeveloper earned 400 total points
ID: 13470026
did u bind ur grid in Page_Load whe Page.IsPostBack = false ?
0
 

Author Comment

by:jericho_law
ID: 13470033
where can i check that out?
0
 

Author Comment

by:jericho_law
ID: 13470055
Thanks!
I managed to solve it now. I left out the page load binding:
----------------------------------------------------------------------------------
If Page.IsPostBack = False Then
....
End if
----------------------------------------------------------------------------------

Now i have another issue.
I wanted do a delete of my database.
But there's a error to it.

--------------------- my vb -----------------------------
        Dim conAuthors As OleDbConnection
        Dim strDelete As String
        Dim cmdDelete As OleDbCommand

        conAuthors = New OleDbConnection(strConn)
        strDelete = "Delete From prescription Where nric='" & Session("payment") & "'"
        cmdDelete = New OleDbCommand(strDelete, conAuthors)
        conAuthors.Open()
        cmdDelete.ExecuteNonQuery()
        conAuthors.Close()
---------------------------------------------------------------

--------------- error -------------------------

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.Data.OleDb.OleDbException: Could not delete from specified tables.

Source Error:

Line 74:         cmdDelete = New OleDbCommand(strDelete, conAuthors)
Line 75:         conAuthors.Open()
Line 76:         cmdDelete.ExecuteNonQuery()
Line 77:         conAuthors.Close()
Line 78:
 
Source File: c:\inetpub\wwwroot\Clinic\payment.aspx.vb    Line: 76

Stack Trace:

   [OleDbException (0x80004005): Could not delete from specified tables.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
   Clinic.payment.Button2_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\Clinic\payment.aspx.vb:76
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   System.Web.UI.Page.ProcessRequestMain()
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 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