Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. GridView FindControl LINQ Update

GridView FindControl LINQ Update

Scheduled Pinned Locked Moved C#
csharpdatabaselinqsecurityannouncement
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RickSharp
    wrote on last edited by
    #1

    Hey Guys, I know I can access my ItemTemplated Checkbox this way:

    foreach (GridViewRow rowItem in GridView1.Rows)
    {

    CheckBox ckBxSelect = ((CheckBox)rowItem.FindControl("chkBxSelect"));  
    
    
    // chk.checked will access the checkbox state on button click event  
    if (ckBxSelect.Checked)  
    {  
        Response.Write("True");  
    }  
    

    }

    Ive built 1 LINQ object joined from 2 Datatables which comes from 2 WebServices. My GridView is bound to my LINQ object. When the user clicks submit, a foreach loop inserts that LINQ object into my database like so:

    protected void Button1_Click(object sender, EventArgs e)
    {
    mySQLDatabaseDataContext dbc = new mySQLDatabaseDataContext("Data Source=JBBBZ7V1\\SQLEXPRESS;Initial Catalog=WLSData;Integrated Security=True");

            mySQLTableName newRecord;           
            foreach (var item in LINQobject)
            {
                newRecord = new mySQLTableName();
    
    
                newRecord.CustName = forAppr.custName;
                newRecord.Status = "";          
                newRecord.DateTimeSubmitted = DateTime.Now;
    
                dbc.mySQLTableName.InsertOnSubmit(newRecord);
    
            }
    
            dbc.SubmitChanges();
    

    }

    Like I said, my checkbox is in a TemplateField like so:

                        <HeaderTemplate>
                            </HeaderTemplate>
                         
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
    

    When I am inserting from my LINQ object, I would like the "Status" field to update with "True" if checkbox is checked or "False" if checkbox is not checked. Like so:

    protected void Button1_Click(object sender, EventArgs e)
    {
    mySQLDatabaseDataC

    R L 2 Replies Last reply
    0
    • R RickSharp

      Hey Guys, I know I can access my ItemTemplated Checkbox this way:

      foreach (GridViewRow rowItem in GridView1.Rows)
      {

      CheckBox ckBxSelect = ((CheckBox)rowItem.FindControl("chkBxSelect"));  
      
      
      // chk.checked will access the checkbox state on button click event  
      if (ckBxSelect.Checked)  
      {  
          Response.Write("True");  
      }  
      

      }

      Ive built 1 LINQ object joined from 2 Datatables which comes from 2 WebServices. My GridView is bound to my LINQ object. When the user clicks submit, a foreach loop inserts that LINQ object into my database like so:

      protected void Button1_Click(object sender, EventArgs e)
      {
      mySQLDatabaseDataContext dbc = new mySQLDatabaseDataContext("Data Source=JBBBZ7V1\\SQLEXPRESS;Initial Catalog=WLSData;Integrated Security=True");

              mySQLTableName newRecord;           
              foreach (var item in LINQobject)
              {
                  newRecord = new mySQLTableName();
      
      
                  newRecord.CustName = forAppr.custName;
                  newRecord.Status = "";          
                  newRecord.DateTimeSubmitted = DateTime.Now;
      
                  dbc.mySQLTableName.InsertOnSubmit(newRecord);
      
              }
      
              dbc.SubmitChanges();
      

      }

      Like I said, my checkbox is in a TemplateField like so:

                          <HeaderTemplate>
                              </HeaderTemplate>
                           
                          <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
      

      When I am inserting from my LINQ object, I would like the "Status" field to update with "True" if checkbox is checked or "False" if checkbox is not checked. Like so:

      protected void Button1_Click(object sender, EventArgs e)
      {
      mySQLDatabaseDataC

      R Offline
      R Offline
      RickSharp
      wrote on last edited by
      #2

      This link shed a little light, but still confused how to implement it. http://stackoverflow.com/questions/1233916/linq-find-all-checked-checkboxes-in-a-gridview[^]

      1 Reply Last reply
      0
      • R RickSharp

        Hey Guys, I know I can access my ItemTemplated Checkbox this way:

        foreach (GridViewRow rowItem in GridView1.Rows)
        {

        CheckBox ckBxSelect = ((CheckBox)rowItem.FindControl("chkBxSelect"));  
        
        
        // chk.checked will access the checkbox state on button click event  
        if (ckBxSelect.Checked)  
        {  
            Response.Write("True");  
        }  
        

        }

        Ive built 1 LINQ object joined from 2 Datatables which comes from 2 WebServices. My GridView is bound to my LINQ object. When the user clicks submit, a foreach loop inserts that LINQ object into my database like so:

        protected void Button1_Click(object sender, EventArgs e)
        {
        mySQLDatabaseDataContext dbc = new mySQLDatabaseDataContext("Data Source=JBBBZ7V1\\SQLEXPRESS;Initial Catalog=WLSData;Integrated Security=True");

                mySQLTableName newRecord;           
                foreach (var item in LINQobject)
                {
                    newRecord = new mySQLTableName();
        
        
                    newRecord.CustName = forAppr.custName;
                    newRecord.Status = "";          
                    newRecord.DateTimeSubmitted = DateTime.Now;
        
                    dbc.mySQLTableName.InsertOnSubmit(newRecord);
        
                }
        
                dbc.SubmitChanges();
        

        }

        Like I said, my checkbox is in a TemplateField like so:

                            <HeaderTemplate>
                                </HeaderTemplate>
                             
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
        

        When I am inserting from my LINQ object, I would like the "Status" field to update with "True" if checkbox is checked or "False" if checkbox is not checked. Like so:

        protected void Button1_Click(object sender, EventArgs e)
        {
        mySQLDatabaseDataC

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        RickSharp wrote:

        This code will throw an exception because of the object not being set to a reference.

        Then you need to fix that bug. Glancing at your code it seems you are using the variable ckBxSelect without setting it to refer to any object.

        R 1 Reply Last reply
        0
        • L Lost User

          RickSharp wrote:

          This code will throw an exception because of the object not being set to a reference.

          Then you need to fix that bug. Glancing at your code it seems you are using the variable ckBxSelect without setting it to refer to any object.

          R Offline
          R Offline
          RickSharp
          wrote on last edited by
          #4

          The only way I know how to refer to a checkbox in a TemplateField is by using GridViewRow in a foreach loop. If there is another way to find that control then i would love to know.

          L 1 Reply Last reply
          0
          • R RickSharp

            The only way I know how to refer to a checkbox in a TemplateField is by using GridViewRow in a foreach loop. If there is another way to find that control then i would love to know.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            I don't know what relevance this has to do with my comment. If you do not understand the error "object not being set to a reference", then I would suggest rereading your C# documentation on objects and references.

            R 1 Reply Last reply
            0
            • L Lost User

              I don't know what relevance this has to do with my comment. If you do not understand the error "object not being set to a reference", then I would suggest rereading your C# documentation on objects and references.

              R Offline
              R Offline
              RickSharp
              wrote on last edited by
              #6

              Thanks for the insight. I'll go reread my C# manual... So i read it, and I guess I'm too stupid to understand it. Maybe someone else can help.

              R 1 Reply Last reply
              0
              • R RickSharp

                Thanks for the insight. I'll go reread my C# manual... So i read it, and I guess I'm too stupid to understand it. Maybe someone else can help.

                R Offline
                R Offline
                RickSharp
                wrote on last edited by
                #7

                I have resolved this issue by reading an asp lablel key into a dictionary. then if the dictionary had that label insert into my database. Sorry if I was vague but I'm very new to all of this so I mostly i just make others made by asking inane questions that are apparently to unclear to understand. :(

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups