Ciao a tutti
sto lavorando sulla gridview per spostare le righe ordinandole in modo personalizzato ma non riesco a far funzionare il codice (non uso database)
Potete aiutarmi???
il codice aspx è questo
il codice .cs è cosi
#region Page_Load
protected void Page_Load(object sender, EventArgs e)
{
_settings = ExtensionManager.GetSettings("FeaturedPostsRotator");
_featuredPostsImages = ExtensionManager.GetSettings("FeaturedPostsImages");
if (!Page.IsPostBack && !Page.IsCallback)
{
BindPosts();
BindSettingsForm();
}
BindGrid();
btnSaveSettings.Click += new EventHandler(btnSaveSettings_Click);
btnUploadImage.Click += new EventHandler(btnUploadImage_Click);
}
#endregion
#region BindGrid
protected void BindGrid()
{
gridFeaturedPostImages.DataKeyNames = new string[] { _featuredPostsImages.KeyField };
gridFeaturedPostImages.DataSource = _featuredPostsImages.GetDataTable();
gridFeaturedPostImages.DataBind();
}
#endregion
#region BindSettingsForm()
protected void BindSettingsForm()
{
chkUseJquery.Checked = false;
if (bool.Parse(_settings.GetSingleValue("UseExtensionJQuery")))
{
chkUseJquery.Checked = true;
}
}
#endregion
#region BindPosts
private void BindPosts()
{
posts.Sort(delegate(Post p1, Post p2) { return String.Compare(p1.Title, p2.Title); });
ddPosts.DataSource = posts;
ddPosts.DataTextField = "Title";
ddPosts.DataValueField = "Id";
ddPosts.DataBind();
}
#endregion
#region MoveGridViewRows
protected void MoveGridViewRows(object sender, EventArgs e)
{
//DataTable dt = new DataTable();
// DataTable dtnew = new DataTable();
Button btnUp = (Button)sender;
GridViewRow row = (GridViewRow)btnUp.NamingContainer;
// Get all items except the one selected
var rows = gridFeaturedPostImages.Rows.Cast<GridViewRow>().Where(a => a != row).ToList();
switch (btnUp.CommandName)
{
case "Up":
//If First Item, insert at end (rotating positions)
if (row.RowIndex.Equals(0))
rows.Add(row);
else
rows.Insert(row.RowIndex - 1, row);
break;
case "Down":
//If Last Item, insert at beginning (rotating positions)
if (row.RowIndex.Equals(gridFeaturedPostImages.Rows.Count - 1))
rows.Insert(0, row);
else
rows.Insert(row.RowIndex + 1, row);
break;
}
}
#endregion