日期:2014-05-18  浏览次数:20476 次

GridView 和 DetailView具有从属关系的一个例子
asp.net学习到DetailView控件的时候课本上有一个例子,自己试着编写,没达到文中的效果,不知什么原因,求解释
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Example.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <table>
  <tr>
  <td>
  <asp:GridView ID="GridView1" runat="server" EnableModelValidation="True" 
  AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
  <Columns>
  <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="false" ReadOnly="true" SortExpression="ID" />
  <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
  <asp:CommandField HeaderText="Select" ShowSelectButton="True" />
  </Columns>
  </asp:GridView>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  ConnectionString="<%$ ConnectionStrings:ProductConnectionString %>" 
  SelectCommand="SELECT ID,Name FROM [UserInfo]"></asp:SqlDataSource>
  </td>
  <td>
  <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="155px" HeaderText="用户详细信息">
  </asp:DetailsView>
  <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
  ConnectionString="<%$ ConnectionStrings:ProductConnectionString %>" 
  SelectCommand="select * from UserInfo where ID=@ID">
  <SelectParameters>
  <asp:ControlParameter ControlID="GridView1" Name="ID" 
  PropertyName="SelectedValue" />
  </SelectParameters>
  </asp:SqlDataSource>
  </td>
  </tr>
  </table>
  </div>
  </form>
</body>
</html>

目标效果:点击GridView控件中的【选择】超链接时,弹出用户的详细信息
实际:只显示了GridView中信息,没有弹出详细信息


------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[8].Attributes.Add("onclick", "return confirm('确认删除!')");
}
}

return confirm('确认删除!) 这块改一下! 行绑定事件!