c# – 使用箭头更改ASP.NET中GridView中显示内容的顺序
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 使用箭头更改ASP.NET中GridView中显示内容的顺序,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3414字,纯文字阅读大概需要5分钟。
内容图文
![c# – 使用箭头更改ASP.NET中GridView中显示内容的顺序](/upload/InfoBanner/zyjiaocheng/775/93c561bdf3b240258e55a3bee54d259b.jpg)
嗨,大家好,
我正在尝试使用表示箭头的图像,以允许用户更改项目在ASP.NET中的网格视图中的列表中显示的顺序.
我有一个类名为“position”的类,该类显示在GridView中并按位置排序.在网格视图的每一行中都有一个向上和向下箭头,我想要改变网格视图行所代表的对象的“位置”值.这是最简单的方法吗?
ASP –
<br /><strong>Previous Employment: </strong> <br />
Pick one of your previous employers listed below to update/delete or <asp:HyperLink ID="PreviousEmploymentLink" runat="server" />.
<asp:GridView runat="server" ID="EmploymentDataGrid" AutoGenerateColumns="false" OnRowDeleting="EmploymentDataGrid_onDeleting"
DataKeyNames="EmployerId" SkinID="FullWidthGrid" >
<EmptyDataTemplate>
<p>No Previous Employment added yet</p>
</EmptyDataTemplate>
<Columns>
<asp:BoundField HeaderText="Dates" DataField="Dates" />
<asp:BoundField HeaderText="Employer's Name" DataField="EmployerName" />
<asp:BoundField HeaderText="Job Description" DataField="JobDescription" />
<asp:BoundField HeaderText="Job Title" DataField="JobTitle" />
<asp:HyperLinkField HeaderStyle-Width="30px" DataNavigateUrlFields="EmployerId"
HeaderText="Edit" Text="<img src='../../../Images/edit.gif' alt='Edit Employment' border='0'/>"
DataNavigateUrlFormatString="UpdatePreviousEmployment.aspx?PreviousEmploymentId={0}" />
<asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="45px">
<ItemTemplate>
<asp:ImageButton AlternateText="Delete User" ID="DeleteButton" runat="server" CommandName="Delete" ImageUrl="~/Images/delete.gif" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Position" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="45px">
<ItemTemplate>
<asp:ImageButton AlternateText="Move Up" ID="UpPositionButton" runat="server" CommandName="MoveEmploymentUp" OnClick="MoveEmploymentUp" ImageUrl="~/Images/arrow_up_green.gif" />
<asp:ImageButton AlternateText="Move Down" ID="DownPositionButton" runat="server" CommandName="MoveEmploymentDown" ImageUrl="~/Images/arrow_down_green.gif" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
谢谢!
解决方法:
protected void MoveEmploymentUp(object sender, ImageClickEventArgs e)
{
ICVDao cvdao = DaoFactory.GetCVDao();
CV currentCv = cvdao.GetById(Int32.Parse(Request.Params["CVID"]), false);
IEmployerDao eDao = DaoFactory.GetEmployerDao();
ImageButton i = (ImageButton)sender;
/*
* if chap above
* Swap numbers with chap above
* if not
* dont swap
*/
GridViewRow g = (GridViewRow)i.Parent.Parent;
Employer emp = (Employer)g.DataItem;
EmploymentDataGrid.SelectedIndex = g.RowIndex;
Employer movingEmployment = eDao.GetById(int.Parse(EmploymentDataGrid.SelectedDataKey.Value.ToString()), false);
Employer otherEmployment = new Employer();
if (movingEmployment.Position != 1 && currentCv.Employment.Count > 1)
{
foreach (Employer em in currentCv.Employment)
{
if (em.Position == movingEmployment.Position - 1)
otherEmployment = em;
}
movingEmployment.Position -= 1;
otherEmployment.Position += 1;
eDao.SaveOrUpdate(movingEmployment);
eDao.CommitChanges();
eDao.SaveOrUpdate(otherEmployment);
eDao.CommitChanges();
EmploymentGridBind();
//InstructionsLabel.Text = "Mover Dates:" +movingEmployment.Dates+ " ID:" + movingEmployment.EmployerId + " Position:" + movingEmployment.Position +
// "<br />Other Dates:" + otherEmployment.Dates + " ID:" + otherEmployment.EmployerId + " Position:" + otherEmployment.Position;
}
}
不得不通过gridview对象而不是gridviewrow获取datakey值,使用它,其余的很容易
内容总结
以上是互联网集市为您收集整理的c# – 使用箭头更改ASP.NET中GridView中显示内容的顺序全部内容,希望文章能够帮你解决c# – 使用箭头更改ASP.NET中GridView中显示内容的顺序所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。