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. Web Development
  3. ASP.NET
  4. repeater with multiple rows

repeater with multiple rows

Scheduled Pinned Locked Moved ASP.NET
databasehelpannouncement
6 Posts 3 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.
  • M Offline
    M Offline
    m dhu
    wrote on last edited by
    #1

    im using repeater control retrieving a table with four rows from sql. one column is to active or inactive the users, when i click on linkbutton to active or inactive single user all users are activated or deactivated. following is the code.... in sql table i had column active with values '1'(active) and '0'(inactive) help me what im missing or any sample code....

    in repeater item command
    //sql connection
    //datatable
    //dataset
    //sql command...
    if(commandname=="inactive")
    foreach (DataRow row in dt.Rows)
    {
    if (row["Active"].ToString() == "0")
    {
    //query for updating//
    update tb_staff set Active=1 where Active=0
    }
    if (row["InActive"].ToString() == "1")
    {
    //query for updating//
    update tb_staff set Active=0 where Active=1
    }

    }

    J P 2 Replies Last reply
    0
    • M m dhu

      im using repeater control retrieving a table with four rows from sql. one column is to active or inactive the users, when i click on linkbutton to active or inactive single user all users are activated or deactivated. following is the code.... in sql table i had column active with values '1'(active) and '0'(inactive) help me what im missing or any sample code....

      in repeater item command
      //sql connection
      //datatable
      //dataset
      //sql command...
      if(commandname=="inactive")
      foreach (DataRow row in dt.Rows)
      {
      if (row["Active"].ToString() == "0")
      {
      //query for updating//
      update tb_staff set Active=1 where Active=0
      }
      if (row["InActive"].ToString() == "1")
      {
      //query for updating//
      update tb_staff set Active=0 where Active=1
      }

      }

      J Offline
      J Offline
      janani13
      wrote on last edited by
      #2

      Hi, You have to update the table with 'update tb_staff set Active=0 where ID=command argument'. Please send the id of the corresponding record to the link button as commmand argument.

      M 1 Reply Last reply
      0
      • M m dhu

        im using repeater control retrieving a table with four rows from sql. one column is to active or inactive the users, when i click on linkbutton to active or inactive single user all users are activated or deactivated. following is the code.... in sql table i had column active with values '1'(active) and '0'(inactive) help me what im missing or any sample code....

        in repeater item command
        //sql connection
        //datatable
        //dataset
        //sql command...
        if(commandname=="inactive")
        foreach (DataRow row in dt.Rows)
        {
        if (row["Active"].ToString() == "0")
        {
        //query for updating//
        update tb_staff set Active=1 where Active=0
        }
        if (row["InActive"].ToString() == "1")
        {
        //query for updating//
        update tb_staff set Active=0 where Active=1
        }

        }

        P Offline
        P Offline
        praveen c byzan com
        wrote on last edited by
        #3

        hi, you will have to find the row no of that row and then use query

        1 Reply Last reply
        0
        • J janani13

          Hi, You have to update the table with 'update tb_staff set Active=0 where ID=command argument'. Please send the id of the corresponding record to the link button as commmand argument.

          M Offline
          M Offline
          m dhu
          wrote on last edited by
          #4

          table with columns id, username, pwd, active, email

          //query what i had is//
          update table tb_staff set active=1 where active=0

          how should i give command argument as link id in query..

          J 1 Reply Last reply
          0
          • M m dhu

            table with columns id, username, pwd, active, email

            //query what i had is//
            update table tb_staff set active=1 where active=0

            how should i give command argument as link id in query..

            J Offline
            J Offline
            janani13
            wrote on last edited by
            #5

            How did you bind the repeater control.Have you used #Eval("id") or databinde r.use the same in the linkbutton.

            at the codebehind , Use item command method to get the commandargument(e.commandargument).you can now get the id.Now you can update the table.Why you have written the query in the page itself.Please prefer to write stored procedures.

            M 1 Reply Last reply
            0
            • J janani13

              How did you bind the repeater control.Have you used #Eval("id") or databinde r.use the same in the linkbutton.

              at the codebehind , Use item command method to get the commandargument(e.commandargument).you can now get the id.Now you can update the table.Why you have written the query in the page itself.Please prefer to write stored procedures.

              M Offline
              M Offline
              m dhu
              wrote on last edited by
              #6

              now its completely not workin

              if (e.CommandName == "act" && e.CommandArgument=="StaffId")
              {
              //sql conn
              //sql comm ("select * from tb_staff"
              DataSet ds = new DataSet();
              DataTable dt = new DataTable();
              OleDbDataAdapter ad = new OleDbDataAdapter(cm);
              ad.Fill(ds, "tb_staff");
              dt = ds.Tables["tb_staff"];
              foreach (DataRow row in dt.Rows)
              {
              if (row["Active"].ToString() == "1")
              {
              SqlCommand cmd = new SqlCommand("update_staff_active", cnn);
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.Add("@StaffId", SqlDbType.Char).Value = "StaffId";
              cmd.Parameters.Add("@Active", SqlDbType.Char).Value = "active";

                                      SqlCommand cmd = new SqlCommand("update\_staff\_active", cnn);
                                      cmd.CommandType = CommandType.StoredProcedure;
                                      cmd.Parameters.Add("@StaffId", SqlDbType.Char).Value = "TextBox1.Text";
                                      cmd.Parameters.Add("@Active", SqlDbType.Char).Value = "TextBox2.Text";
                                      cnn.Open();
                                      cmd.ExecuteNonQuery();
                                      cnn.Close();
                         
                                     
                                  }
                              }
                          }
              

              procedure create PROCEDURE [dbo].[update_staff_active] ( @StaffId int , @Active [char] ) AS update tb_staff set Active=@Active where StaffId=@StaffId

              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