gridview 数据绑定后,我加了两个模板列LinkButton,"上移"和"下移" 我现在已经搞定了RowCreated 和 RowCommand
当点击某行的linkbutton时,我可以知道当前的行号我有一个按钮,是循环gridview 按表格里的顺序 更新库里的排序号我想点击"上移"或"下移"时,让这两行的内容交换位置,这个如何实现?
有好的方法吗?
当点击某行的linkbutton时,我可以知道当前的行号我有一个按钮,是循环gridview 按表格里的顺序 更新库里的排序号我想点击"上移"或"下移"时,让这两行的内容交换位置,这个如何实现?
有好的方法吗?
解决方案 »
- WebHtmlEditor1.6.dll是什么
- ?????偶尔出现的问题,大家帮我提示提示,大概是什么原因?????
- 80分求解 HttpContext.Current.Request.Cookies的问题?
- 初学者想提个问题,希望大家能帮帮我,谢谢
- 一个奇怪的图片路径问题
- ***现在的电子商务网站一般都是用什么语言开发的?进来聊聊***
- asp.net button点击有删除提示
- 大家帮帮我,找一张精华贴啊!怎么“该页无法显示”??GumPGZ发的
- 一个关于aspnet_wp.exe进程的问题
- 这一错误是因为提交的内容中有“<”“>”造成的,如何让它不检测“<>”?
- 这个有关二级联动的代码,怎么将它放入.js文件中。然后引用它啊。。
- 哪位大哥发给我一份关于纯粹B/S方式实现InfoPath的设计和运行时的源码?谢谢
然后把这行删了,然后再在另一行的上面或者下面插入一行
然后在把这些值放回去以前用vb6写winform 的程序的时候,是这样写的,但是asp.net就不会了
<asp:LinkButton ID="uplinkbtn" CommandName="up" CommandArgument='<%# Eval("subjectid") %>' OnClientClick='return confirm("确定上移吗?")' runat="server">向上移动</asp:LinkButton>
<asp:LinkButton ID="downlinkbtn" CommandName="down" CommandArgument='<%# Eval("subjectid") %>' OnClientClick='return confirm("确定下移吗?")' runat="server">向下移动</asp:LinkButton>
======ItemCommend事件里面.cs代码
private static LinkButton linkbtn, linkbtn1;
/// <summary>
/// RP命令事件
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
protected void DLBlogSubjectList_ItemCommand(object source, RepeaterCommandEventArgs e)
{
Repeater repeater;
switch (e.CommandName)
{
case "del":
linkbtn = (LinkButton)e.Item.FindControl("dellinkbtn");
if (BLL.BSubject.DelSubject(Convert.ToInt32(linkbtn.CommandArgument)))
{
Common.JScript.Alert("删除成功!");
}
else
{
Common.JScript.Alert("删除失败!");
}
iniDataList(this.getFormParm("sqlWhere"));
break;
case "modify":
swin2.Visible = true;
linkbtn = (LinkButton)e.Item.FindControl("modifylinkbtn");
break;
case "up":
linkbtn = (LinkButton)e.Item.FindControl("uplinkbtn");
repeater = (Repeater)source;
if (e.Item.ItemIndex > 0)
{
linkbtn1 = (LinkButton)repeater.Items[e.Item.ItemIndex - 1].FindControl("uplinkbtn");
if (BLL.BSubject.UpSubjectOrderNum(Convert.ToInt32(linkbtn.CommandArgument), Convert.ToInt32(linkbtn1.CommandArgument)))
{
Common.JScript.Alert("向上移动成功!");
}
else
{
Common.JScript.Alert("向上移动失败!");
}
iniDataList(this.getFormParm("sqlWhere"));
}
else
{
Common.JScript.Alert("已经是最上面一级了!");
}
break;
case "down":
linkbtn = (LinkButton)e.Item.FindControl("downlinkbtn");
repeater = (Repeater)source;
if (e.Item.ItemIndex + 1 < repeater.Items.Count)
{
linkbtn1 = (LinkButton)repeater.Items[e.Item.ItemIndex + 1].FindControl("uplinkbtn");
if (BLL.BSubject.UpSubjectOrderNum(Convert.ToInt32(linkbtn.CommandArgument), Convert.ToInt32(linkbtn1.CommandArgument)))
{
Common.JScript.Alert("向下移动成功!");
}
else
{
Common.JScript.Alert("向下移动失败!");
}
iniDataList(this.getFormParm("sqlWhere"));
}
else
{
Common.JScript.Alert("已经是最下面一级了!");
}
break;
}
}
移动行的代码是不是在那里面写的呢?
{
Control cmdSource = e.CommandSource as Control;
GridViewRow row = cmdSource.NamingContainer as GridViewRow;
int rowIndex = row.RowIndex;
int id=Convert.ToInt32(GridView1.DataKeys[rowIndex].Value);//得到本行ID
//要得到上一行的,就拿rowindex-1,下一行的就rowindex+1
}
直接操作内存中的dataset就可以,点击 上 下 按钮,移动内存中的dataset对应行的位置,知道点击"保存",再循环dataset ,保存到数据库中
DataSet就是个DataTable的容器,你直接操作里面的DataTable 比如删除行, Remove 表克隆 Clone 添加行 AddRow......
以前我写的一个 上下移动ListBox内条目的代码,是内存操作,确认后,才提交
不过是vb的.呵呵 #Region " 移动右侧元素"
'_up向上移,如果是false,则向下
Private Sub MoveUp(ByVal _up As Boolean)
Try
If Me.lbox_have.SelectedIndex = -1 Then
Exit Sub
End If '记录选择是第几行,方便最后再设置选择
Dim index As Integer
index = Me.lbox_have.SelectedIndex
'读取右侧选择的数据 并移出 Dim dt_Have As DataTable
dt_Have = CType(ViewState("HaveDataTable"), DataTable)
ViewState("HaveDataTable") = Nothing '定义临时表
Dim dt_temp As DataTable
'克隆表结构
dt_temp = dt_Have.Clone()
'清除数据
dt_temp.Clear() '循环复制
Dim i As Integer
For i = 0 To dt_Have.Rows.Count - 1
If _up = True Then
'如果是向上运动
If CType(dt_Have.Rows(i)("CTID"), String) = Me.lbox_have.SelectedValue.ToString() And i <> 0 Then
'如果是选中行,则将当前datatable最后一个元素与它作交换,
dt_temp.Rows.Remove(dt_temp.Rows(i - 1))
dt_temp.Rows.Add(dt_Have.Rows(i).ItemArray)
'将以前最后一行数据加上
dt_temp.Rows.Add(dt_Have.Rows(i - 1).ItemArray)
Else
'如果不是当前选中行,则直接顺序复制到临时表中
dt_temp.Rows.Add(dt_Have.Rows(i).ItemArray)
End If
Else
'如果是向下运动
If CType(dt_Have.Rows(i)("CTID"), String) = Me.lbox_have.SelectedValue.ToString() And i <> dt_Have.Rows.Count - 1 Then
'如果是选中行,则将源datatable下一个元素与它作交换,
'先添加下一个元素
dt_temp.Rows.Add(dt_Have.Rows(i + 1).ItemArray)
'再添加选中元素
dt_temp.Rows.Add(dt_Have.Rows(i).ItemArray)
i = i + 1
Else
'如果不是当前选中行,则直接顺序复制到临时表中
dt_temp.Rows.Add(dt_Have.Rows(i).ItemArray)
End If
End If
Next ViewState("HaveDataTable") = dt_temp '重新绑定
band() '如果是向上移动,则不允许超过顶部
If _up = True And index > 0 Then
index = index - 1
End If '如果是向下移动,则不允许超过底部
If _up = False And index < dt_Have.Rows.Count - 1 Then
index = index + 1
End If Me.lbox_have.SelectedIndex = index Catch ex As Exception End Try
End Sub
#End Region