关于主GridView模版列嵌套从GridView
grt 2008-03-07 03:16:26 我做了GridView模版列嵌套GridView显示主从表数据,运行时无错误提示,可结果是从表不出现,不知什么原因。
原码贴出,帮助指正:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Aqsg.ascx.cs" Inherits="sgdw_UserControl_Aqsg" %>
<div>
</div>
<div id="事故" style="width: 100%; border: 1px;">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="code" DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowSelectButton="True">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:CommandField>
<asp:BoundField DataField="code" HeaderText="系统号" InsertVisible="False" ReadOnly="True"
SortExpression="code" />
<asp:BoundField DataField="sg_date" HeaderText="事故时间" SortExpression="sg_date" />
<asp:BoundField DataField="bg_sgdw" HeaderText="事故单位" SortExpression="bg_sgdw" />
<asp:BoundField DataField="project" HeaderText="工程项目" SortExpression="project" />
<asp:BoundField DataField="js_yy" HeaderText="大致经过" SortExpression="js_yy" />
<asp:TemplateField HeaderText="伤亡人员">
<ItemTemplate>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="code,id" DataSourceID="SqlDataSource2" AllowSorting="True">
<Columns>
<asp:BoundField DataField="code" HeaderText="系统号" ReadOnly="True" SortExpression="code" />
<asp:BoundField DataField="id" HeaderText="序号" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="sg_name" HeaderText="姓名" SortExpression="sg_name" />
<asp:BoundField DataField="sex" HeaderText="性别" SortExpression="sex" />
<asp:BoundField DataField="nl" HeaderText="年龄" SortExpression="nl" />
<asp:BoundField DataField="gz" HeaderText="工种" SortExpression="gz" />
<asp:BoundField DataField="sglb" HeaderText="事故类别" SortExpression="sglb" />
<asp:BoundField DataField="swcd" HeaderText="伤亡程度" SortExpression="swcd" />
</Columns>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" Wrap="False" Font-Bold="False"
Font-Size="10pt" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#FFEEAA" Font-Bold="False" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Left" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="False" ForeColor="White" Wrap="False"
Font-Names="宋体" Font-Size="10pt" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:anjzConnectionString %>"
SelectCommand="SELECT [code], [id], [sg_name], [sex], [nl], [gz], [sglb], [swcd] FROM [aqsg_1] WHERE ([code] = @code)">
<SelectParameters>
<asp:Parameter Name="code" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="remarks" HeaderText="备案" SortExpression="remarks" />
</Columns>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" Wrap="False" Font-Bold="False"
Font-Size="10pt" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#FFEEAA" Font-Bold="False" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Left" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="False" ForeColor="White" Wrap="False"
Font-Names="宋体" Font-Size="10pt" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:anjzConnectionString %>"
SelectCommand="SELECT [code], [sg_date], [bg_sgdw], [project], [js_yy], [remarks] FROM [aqsg] ORDER BY [sg_date] DESC">
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</div>
///////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class sgdw_UserControl_Aqsg : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > -1)
{
SqlDataSource DS = e.Row.FindControl("SqlDataSource2") as SqlDataSource;
DS.SelectParameters["code"].DefaultValue = e.Row.Cells[0].Text;
}
}
}