用detailsview显示gridview 选择的详细信息
帮我看一下有什么问题 目前是gridview 选择之后detailsview仍旧没有出现前面还经常在删除时报错 或者说该字符串未被识别为有效的日期时间 有一个从索引 0 处开始的未知字 我定义的是datetime型
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>后台管理页面</title>
</head>
<body>
<form id="Form1" runat="server">
<div style="text-align: center; background-image: url(Images/Main/BackColor.jpg);">
<table border="1" style="border-right: thin groove; border-top: thin groove; border-left: thin groove;
border-bottom: thin groove" width="948">
<tr>
<td style="width: 94px; position: static; height: 26px; text-align: left" valign="middle">
<asp:Image ID="Image1" runat="server" Height="55px" ImageUrl="~/Images/Main/logo1.jpg"
Width="81px" /></td>
<td style="width: 900px; position: static; height: 26px; text-align: right;" valign="middle">
<asp:Button ID="Button1"
runat="server" OnClick="Button1_Click" Text="退出后台" />
</td>
</tr>
<tr>
<td colspan="2" style="vertical-align: top; position: static; height: 450px; text-align: left"
valign="middle" enableviewstate="true">
<div style="text-align: center">
</div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1" DataKeyNames="comment_user_name,comment_submit_time">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="comment_user_name" HeaderText="comment_user_name" ReadOnly="True"
SortExpression="comment_user_name" />
<asp:BoundField DataField="comment" HeaderText="comment" SortExpression="comment" />
<asp:BoundField DataField="comment_submit_time" HeaderText="comment_submit_time"
ReadOnly="True" SortExpression="comment_submit_time" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/database.mdb"
SelectCommand="SELECT [comment_user_name], [comment], [comment_submit_time] FROM [comment]">
</asp:AccessDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="comment_user_name,comment_submit_time" DataSourceID="AccessDataSource2" Height="50px"
Width="125px">
<Fields>
<asp:BoundField DataField="comment_user_name" HeaderText="comment_user_name" ReadOnly="True"
SortExpression="comment_user_name" />
<asp:BoundField DataField="comment_submit_time" HeaderText="comment_submit_time"
ReadOnly="True" SortExpression="comment_submit_time" />
<asp:BoundField DataField="comment" HeaderText="comment" SortExpression="comment" />
<asp:BoundField DataField="user_name" HeaderText="user_name" SortExpression="user_name" />
<asp:BoundField DataField="submit_time" HeaderText="submit_time" SortExpression="submit_time" />
<asp:CommandField ShowDeleteButton="True" />
</Fields>
</asp:DetailsView>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/database.mdb"
DeleteCommand="DELETE FROM [comment] WHERE (([comment_user_name] = ?)AND([comment_submit_time ]= ?) ) "
InsertCommand="INSERT INTO [comment] ([comment_user_name], [comment_submit_time], [comment], [user_name], [submit_time]) VALUES (?, ?, ?, ?, ?)"
SelectCommand="SELECT comment_user_name, comment_submit_time, comment, user_name, submit_time FROM comment WHERE ([comment_user_name] = ?) AND ([comment_submit_time] = ?)"
UpdateCommand="UPDATE [comment] SET [comment] = ?, [user_name] = ?, [submit_time] = ? WHERE (([comment_user_name] = ?)AND ([comment_submit_time] = ?)) ">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="comment_user_name"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="commet_submit_time" PropertyName="SelectedValue" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="comment_user_name" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="comment" Type="String" />
<asp:Parameter Name="user_name" Type="String" />
<asp:Parameter Name="submit_time" Type="DateTime" />
<asp:Parameter Name="comment_user_name" Type="String" />
<asp:Parameter Name="comment_submit_time" Type="DateTime" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="comment_user_name" Type="String" />
<asp:Parameter Name="comment_submit_time" Type="DateTime" />
<asp:Parameter Name="comment" Type="String" />
<asp:Parameter Name="user_name" Type="String" />
<asp:Parameter Name="submit_time" Type="DateTime" />
</InsertParameters>
</asp:AccessDataSource>
</td>
</tr>
<tr>
</tr>
</table>
</div>
</form>
</body>
</html> --------------------编程问答-------------------- 你贴这么多代码 。。。。。想。。干嘛?
通过URL(a标签) 传值
页面接收 通过接受值 查询绑定 --------------------编程问答-------------------- 你的GridView的DataKey有两个值,
所以不能所见即所得地设置AccessDataSource2的SelectParameters,
应该将一下前台代码删除,用后台代码来设置!
应该删除的代码:
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="comment_user_name" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="commet_submit_time" PropertyName="SelectedValue" />
</SelectParameters>
后台设置在GridView1的SelectedIndexChanged事件中:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
AccessDataSource2.SelectParameters["comment_user_name"].DefaultValue = GridView1.SelectedDataKey.Values[0].ToString();
AccessDataSource2.SelectParameters["commet_submit_time"].DefaultValue = GridView1.SelectedDataKey.Values[1].ToString();
}
--------------------编程问答-------------------- 那个楼上的 后天的语言是什么 --------------------编程问答--------------------
如上改了之后
“GridView1_SelectedIndexChanged”不是“ASP.backstage_aspx”的成员。
是什么问题? --------------------编程问答-------------------- GridView1_SelectedIndexChanged是按了选择按钮发生的事件!
具体操作:
点中GridVew,在事件中找到SelectedIndexChanged事件,双击之!
补充:.NET技术 , ASP.NET