美女程序员在线等待您来帮助!!!!

angellan 2008-07-18 03:44:01
怎么实出dateilsvies的更新,我用的是sql语句绑定控件
不知道怎么获取值,更新,我在ItemUpdating事件里写了:
e.NewValues["thingType"],来获取更新后的值,但是不行,thingType是表中的字段名称
...全文
1169 69 打赏 收藏 转发到动态 举报
写回复
用AI写文章
69 条回复
切换为时间正序
请发表友善的回复…
发表回复
花果山小猴 2009-01-19
  • 打赏
  • 举报
回复
美女~~~~~~~~~~
APP开发王 2009-01-05
  • 打赏
  • 举报
回复
....................
wang76_cn 2008-09-01
  • 打赏
  • 举报
回复
是的,假!
night_legend 2008-08-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hubblebubblepig 的回复:]
哈哈哈 标题太假啦
[/Quote]
kuku12bing 2008-07-18
  • 打赏
  • 举报
回复
一群SX
beliveb 2008-07-18
  • 打赏
  • 举报
回复
恩 香瓜好甜哦 对不起 偶在吃东西 呵呵
tinkcn 2008-07-18
  • 打赏
  • 举报
回复
就是不一样。
qpzmxncb 2008-07-18
  • 打赏
  • 举报
回复
应该是在更新的那个模板里用 <%#Bind("thingType")%>
conan304 2008-07-18
  • 打赏
  • 举报
回复
打酱油顺带买王老吉的飘过
满衣兄 2008-07-18
  • 打赏
  • 举报
回复
[Quote=引用楼主 angellan 的帖子:]
怎么实出dateilsvies的更新,我用的是sql语句绑定控件
不知道怎么获取值,更新,我在ItemUpdating事件里写了:
e.NewValues["thingType"],来获取更新后的值,但是不行,thingType是表中的字段名称
[/Quote]
获取更新后的值的代码写在ItemUpdated中.
ItemUpdating是数据更新之前激发.
在设计管理器的属性页的下面有注释,请注意.
yunfeng007 2008-07-18
  • 打赏
  • 举报
回复
假作真时真亦假,无为有处有还无
Krismeng 2008-07-18
  • 打赏
  • 举报
回复
NewValues
好象只有是有数据源控件的是后才能用比如sqldatasource
kong521 2008-07-18
  • 打赏
  • 举报
回复
数据控件越位更新好象不好吧
反正我所做的程序没这么做过
数据都是有添加页面添加进来
数据控件只是用来显示一个列表
点击某信息就打开修改某信息的页面
给用户修改就可以了
很简单的
在说.net2.0的强类型数据集很强大哟
不用实例化那些数据连接操作对象
jacksion520 2008-07-18
  • 打赏
  • 举报
回复
经过我的观察,楼主整个下午都在不停的把帖子提前..........
datahandler2 2008-07-18
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 lovehongyun 的回复:]
dateilsvies
这是什么?
[/Quote]
满衣兄 2008-07-18
  • 打赏
  • 举报
回复
如果LZ是初学,多用一些常见的控件,例如vs2005中的gridview或者vs2003中的datagrid完全可以实现detailsview的功能,常见的控件会用了,那些不常见的自然也就会用了.原理性的东西基本一样的,无非就是读取,绑定.更新的时候就是重新绑定...
kong521 2008-07-18
  • 打赏
  • 举报
回复
[Quote=引用 44 楼 allanmorgan 的回复:]
人气这么高?
美女两字值千金啊!
[/Quote]
只是作个更新而已
为什么直接用数据控件更新呢
你可以放个连接列
点击打开一个新的页面,传个主键编号
在新页面里加载某编号信息
在提供修改功能呀
angellan 2008-07-18
  • 打赏
  • 举报
回复
e.NewValues["ThingType"].ToString()这样会报错,错误是:未将对象引用设置到对象的实例。
满衣兄 2008-07-18
  • 打赏
  • 举报
回复
后台代码:
public partial class Admin_Module_Comment_ManageComment : System.Web.UI.Page 

{

Comment myComment = new Comment();

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{ //设置当前排序方式

ViewState["SortOrder"] = "AddDate";

ViewState["OrderDire"] = "ASC";

//绑定GridView和DetailsView数据

BindData();



}

}

//当GridView单击选择时 DetailsView1显示详细数据

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

{



this.DetailsView1.PageIndex = this.GridView1.SelectedRow.DataItemIndex;

this.DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);

BindDetails();

}

#region 数据绑定



//绑定GridView和DetailsView数据

private void BindData()

{

BindGridView();

BindDetails();



}

//GridView数据源

private void BindGridView()

{

//GetAllComments是自己写的一个方法,返回所有数据

DataSet ds = myComment.GetAllComments();

DataView view = ds.Tables[0].DefaultView;

string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];

view.Sort = sort;

GridView1.DataSource = view;

this.GridView1.DataBind();







}

//Details数据源

private void BindDetails()

{



this.DetailsView1.DataSource = myComment.GetAllComments();

this.DetailsView1.DataBind();

}



#endregion

//DetailsView更新操作

protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)

{



//当使用DataSource 可使用这各方法

//string strReply = e.NewValues["Reply"].ToString();

//int id =Int32.Parse (e.OldValues[0].ToString());



TextBox tb = ((TextBox)DetailsView1.FindControl("txtReply"));

Label lb =((Label)DetailsView1.FindControl("lblId"));

CheckBox ck = ((CheckBox)DetailsView1.FindControl("check"));



string strReply = tb.Text.Trim().ToString();

int id =Int32.Parse ( lb.Text.Trim().ToString());

bool chk = false;

if (ck.Checked)

{

chk = true;

}

else

{

chk = false;

}

//这是一个添加回复方法

myComment.AddReply(id, strReply, chk);

//切换模式

this.DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);

//重新绑定GridView和DetailsView数据

BindData();



}

//gridview分页

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

this.GridView1.PageIndex = e.NewPageIndex;

BindGridView();

}

// 判断DetailsView模式

protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e)

{

//判断模式

if (e.NewMode == DetailsViewMode.Edit)

{

DetailsView1.ChangeMode(DetailsViewMode.Edit);

}

if (e.NewMode == DetailsViewMode.Insert)

{

DetailsView1.ChangeMode(DetailsViewMode.Insert);

}

if (e.NewMode == DetailsViewMode.ReadOnly)

{

DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);

}

//绑定数据源

BindDetails();



}

//GridView1删除操作

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

{

//DataKeys应该是一个集合,当GridView加载以后会把指定的值添加到这个集合中,例如ID

int id = Int32.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());

myComment.DeleteComment(id);

BindData();

}



//GridView1排序操作

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)

{



string sPage = e.SortExpression;

if (ViewState["SortOrder"].ToString() == sPage)

{

if (ViewState["OrderDire"].ToString() == "Desc")

ViewState["OrderDire"] = "ASC";

else

ViewState["OrderDire"] = "Desc";

}

else

{

ViewState["SortOrder"] = e.SortExpression;

}

//重新绑定GridView1数据源

BindGridView();

}



}


文章来源:http://www.cnblogs.com/liangwei389/archive/2008/05/02/1179548.html
满衣兄 2008-07-18
  • 打赏
  • 举报
回复
在写一个留言本的后台管理时用到了GridView和DetailsView,顺便把它们的一些用法记下来

主要有GridView的排序操作和DetailsView的更新操作

前台代码:

<body> 

<form id="form1" runat="server">

<table style="width: 100%">

<tr>

<td style="width: 40%; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; padding-top: 0px; text-align: left;" valign="top">

<asp:GridView ID="GridView1" runat="server" Width="100%" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Id" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" PageSize="3" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" OnSorting="GridView1_Sorting">

<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

<Columns>

<asp:BoundField DataField="Title" HeaderText="标题" SortExpression="Title" />

<asp:BoundField DataField="AddDate" HeaderText="添加日期" SortExpression="AddDate" />

<asp:CheckBoxField DataField="IsChecked" HeaderText="通过审核" SortExpression="IsChecked" />

<asp:CommandField ShowSelectButton="True" />

<asp:CommandField ShowDeleteButton="True" />

</Columns>

<RowStyle BackColor="#EFF3FB" />

<EditRowStyle BackColor="#2461BF" />

<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />

<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

<AlternatingRowStyle BackColor="White" />

</asp:GridView>

 

</td>

<td style="width: 60%; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; vertical-align: top; padding-top: 0px; text-align: left;">

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="100%" AutoGenerateRows="False" CellPadding="4" DataKeyNames="Id" ForeColor="#333333" GridLines="None" OnItemUpdating="DetailsView1_ItemUpdating" OnModeChanging="DetailsView1_ModeChanging">

<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />

<EditRowStyle BackColor="#2461BF" />

<RowStyle BackColor="#EFF3FB" />

<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

<Fields>



<asp:TemplateField HeaderText= "ID ">

<EditItemTemplate>

<asp:Label ID="lblID" runat="server" Text='<%# Bind("Id") %>'></asp:Label>

</EditItemTemplate>

<InsertItemTemplate>

<asp:Label ID="lblID" runat="server" Text='<%# Bind("Id") %>'></asp:Label>

</InsertItemTemplate>

<ItemTemplate>

<asp:Label ID="lblID" runat="server" Text='<%# Bind("Id") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>



<asp:BoundField DataField="Student" HeaderText="学生" SortExpression="Student" ReadOnly="True" />

<asp:BoundField DataField="Department" HeaderText="系部" SortExpression="Department" ReadOnly="True" />





<asp:BoundField DataField="Class" HeaderText="班级" SortExpression="Class" ReadOnly="True" />

<asp:BoundField DataField="Qq" HeaderText="QQ" SortExpression="Qq" ReadOnly="True" />

<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" ReadOnly="True" />

<asp:BoundField DataField="Telephone" HeaderText="电话" SortExpression="Telephone" ReadOnly="True" />

<asp:BoundField DataField="Title" HeaderText="标题" SortExpression="Title" ReadOnly="True" />

<asp:BoundField DataField="AddDate" HeaderText="添加日期" SortExpression="AddDate" ReadOnly="True" />





<asp:TemplateField HeaderText= "是否通过审核 ">

<EditItemTemplate>

<asp:CheckBox ID="check" runat="server" Checked='<%# Bind("IsChecked") %>' />

</EditItemTemplate>

<InsertItemTemplate>

<asp:CheckBox ID="check" runat="server" Checked='<%# Bind("IsChecked") %>' />

</InsertItemTemplate>

<ItemTemplate>



<asp:CheckBox ID="check" runat="server" Checked='<%# Bind("IsChecked") %>' />

</ItemTemplate>

</asp:TemplateField>



<asp:BoundField DataField="Content" HeaderText="留言内容" SortExpression="Content" ReadOnly="True" />



<asp:TemplateField HeaderText= "回复内容 ">

<EditItemTemplate>



<asp:TextBox ID="txtReply" runat="server" Text='<%#Bind("Reply") %>' Width="100%" Height="202px" TextMode="MultiLine"></asp:TextBox>

</EditItemTemplate>

<InsertItemTemplate>

<asp:TextBox ID="txtReply" runat="server" Text='<%#Bind("Reply") %>' Width="100%" Height="202px" TextMode="MultiLine"></asp:TextBox>

</InsertItemTemplate>

<ItemTemplate>



<asp:Label ID="lblReply" runat="server" Text='<%#Bind("Reply") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:CommandField ShowEditButton="True" EditText="回复" UpdateText="确定" />



</Fields>

<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />

<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

<AlternatingRowStyle BackColor="White" />



</asp:DetailsView>

</td>

</tr>

</table>

</form>

</body>

加载更多回复(49)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧