Search This Blog

Friday, April 3, 2015

How to change the row index by clicking image up and down

You can get the row ID from OnRowCommand.

 protected void gridview_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            DataTable dt = new DataTable();
            dt = Getdetails();                  ///Get existing details from gridview
            int index = Convert.ToInt32(e.CommandArgument);     ///Get row ID
            string Command = Convert.ToString(e.CommandName); ///Get Commandname
            DataRow selectedRow = dt.Rows[index];                        ///Get the selected Row
            DataRow newRow = dt.NewRow();                                 ///Create a new row
            newRow.ItemArray = selectedRow.ItemArray;   ///Insert selected row into new row
            dt.Rows.Remove(selectedRow);                                      ///Remove selected row
            if (Command == "Up")
            {
                dt.Rows.InsertAt(newRow, index - 1);                    
            }
            else if (Command == "Down")
            {
                dt.Rows.InsertAt(newRow, index + 1);
            }
            gridview.DataSource = dt;
            gridview.DataBind();                             ///Set details into grid again
            ViewState["WFtable"] = dt;
            Setdetails(dt);                
        }


I hope this will help you guys.

thanks.

No comments:

Post a Comment

Restricting Custom People Picker to only one Sharepoint group programatically

Refer the following script files in your page,     <!-- For People Picker -->     <script type="text/javascript" src...