repeater with multiple rows
-
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
}}
-
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
}}
-
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
}}
hi, you will have to find the row no of that row and then use query
-
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.
-
table with columns id, username, pwd, active, email
//query what i had is//
update table tb_staff set active=1 where active=0how should i give command argument as link id in query..
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.
-
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.
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