Problem: RowCommand Event - GridView.FindControls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ananthu
    New Member
    • Sep 2007
    • 87

    Problem: RowCommand Event - GridView.FindControls

    Hi,

    I have a gridview in my web page. I have boundcolumn,che ckboxcolumn and a linkbutton column.

    The commandName of the linkbutton column is "Select"

    The name of the template checkbox is "chkSwapSelect" .

    I want to check the checkbox of the linkbutton clicked row.

    When i click the linkbutton of the gridview RowCommand Event fires

    RowCommand Event Code:
    Code:
    if e.commandName="Select" then
     Dim index as integer=Integer.Parse(e.CommandArgument)
     Dim row as GridVIewRow=dgvAllocation.rows(index)
     dim chk as checkbox
     chk=new checkbox
     chk=ctype(row.FindControl("chkSwapSelect"),checkbox)  // chk returns nothing
     chk.checked=true // object reference not set to an instance of the object
    end if
    The errors are shown as comments in the above code.

    Please help me in finding the controls inside a gridview via RowCommand Event
    Last edited by Frinavale; Mar 19 '10, 02:14 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags and removed bold.
  • Ananthu
    New Member
    • Sep 2007
    • 87

    #2
    Please reply me quickly...

    I am struggling with this task.

    Comment

    • liawcv
      New Member
      • Jan 2009
      • 33

      #3
      ---------- Reply Deleted ----------
      NOTE: Just realized your are using dynamic column. My suggestion may not work... :p

      Comment

      • Ananthu
        New Member
        • Sep 2007
        • 87

        #4
        Please give me the solution for it.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Ananthu,

          Have you tried stepping through your application to make sure that the correct selected index is being used?

          Have you considered using the GridView.Select edIndexChanged Event instead?

          Is the checkbox available at the time when you are trying retrieve the checkbox?
          For example, if the checkbox is in the EditItemTemplat e and is not located in the ItemTemplate then the checkbox is only available if the GridView is in edit mode....it is not available if the GridView is not in edit mode.

          -Frinny

          Comment

          • Ananthu
            New Member
            • Sep 2007
            • 87

            #6
            Hi,

            I have tried with SelectedIndexCh anged Event also. But the same error: Object reference not set to an instance of the object appears to me.

            I haven't tried with GridView Edit mode. Can you please tell me the procedures
            for it and where i have to place my code for checking the checkbox in gridview.

            Any solution for this issue. Please give me.

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Please post the ASP.NET markup for the column that contains the checkbox.

              What I want to see is something that looks like this:
              Code:
              <asp:TemplateField>
                <ItemTemplate>
                  <!-- stuff -->
                </ItemTemplate>
                <EditItemTemplate>
                  <!-- stuff -->
                </EditItemTemplate>
                <!-- etc -->
              </asp:TemplateField>
              You can find this by viewing the ASPX code [Source].
              Please just post the TemplateField item that contains the checkbox.

              Thanks

              -Frinny

              Comment

              • Ananthu
                New Member
                • Sep 2007
                • 87

                #8
                Hi,

                I am not creating the gridview columns in design mode.

                I am creating them at runtime when i click the submit button only.

                I need it like that. This only creates the problem of not finding the control in gridview it seems.

                But i know that in page_preinit event, when i create dynamic grid, there is no problem in finding dynamic controls by a button click.

                Please provide me the solution. I want to create dynamic gridview columns after a button click only and find the controls in it. This is my requirement.

                Please help me.

                Comment

                • Ananthu
                  New Member
                  • Sep 2007
                  • 87

                  #9
                  Hi,

                  I found the answer atlast for this issue.

                  To resolve the error Object reference not set to an instance of the object, again we have to write codings for finding the checkbox controls in gridview in RowCreated event of gridview. If the control is not found means we have to add the checkbox control again in the rows by using,

                  e.rows.cells(in dex).controls.a dd(chk)

                  Now i am able to find checkbox control after selecting the linkbutton in the gridview.

                  Thanks for trying out my issue to this extent.

                  Comment

                  Working...