我正在尝试嵌套两个Grid_Views,如...
<asp:GridView ID="gv" runat="server" CellPadding="0" ForeColor="#333333"
GridLines="None" AutoGenerateColumns="False" Width="100%"
DataSourceID="groupby" OnRowDataBound="RowBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="innerrecs">
<Columns>
<asp:BoundField DataField="date" HeaderText="date" ReadOnly="True"
SortExpression="date" />
<asp:BoundField DataField="mat_no" HeaderText="mat_no"
SortExpression="mat_no" />
<asp:BoundField DataField="injur" HeaderText="injur" SortExpression="injur" />
<asp:BoundField DataField="clm bal" HeaderText="clm bal"
SortExpression="clm bal" />
<asp:BoundField DataField="DOA" HeaderText="DOA" SortExpression="DOA" />
<asp:BoundField DataField="county" HeaderText="county" ReadOnly="True"
SortExpression="county" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="innerrecs" runat="server"
ConnectionString="<%$ ConnectionStrings:TimeMatters10ConnectionString %>" SelectCommand="SELECT CONVERT(CHAR,DATEADD(D, [event].[date], '1800-12-28'),101) as 'date',
[event].mat_no, matter.mat1_01_07 as 'injur', matter.mat1_07_01 as 'clm bal', MAT1_03_08 as 'DOA',replace(matter.mat1_05_03, 'COUNTY OF ', '') as 'county'
FROM lntmuser.[event]
INNER JOIN lntmuser.matter
ON lntmuser.matter.sysid = lntmuser.[event].mat_id
INNER JOIN lntmuser.matter2
ON lntmuser.matter2.sysid = lntmuser.[event].mat_id
WHERE DateDiff(month, Convert(date, CONVERT(CHAR,DATEADD(D, [event].[date], '1800-12-28'),101), 101), GETDATE()) = 1
AND event.con_no = @conno
order by matter.client">
<SelectParameters>
<asp:SessionParameter Name="conno" SessionField="@conno" />
</SelectParameters>
</asp:SqlDataSource>
If You have Any Questions in Reference to this matter please do not hesitate ot contact me.<br /><br />
Thank You,<br />
Dara
<br clear="all" style="page-break-before:always" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="groupby" runat="server"
ConnectionString="<%$ ConnectionStrings:TimeMatters10ConnectionString %>" SelectCommand="SELECT MAX(event.[con_no]) as 'con_no', replace(replace(replace([matter].client, 'P.C.', ''), 'PC', ''), 'INC', '') as 'client',
MAX(mat1_02_02) as 'BillSup', MAX(mat1_02_09) as 'Fax'
, CONVERT(char, GETDATE(), 101) as 'DT'
FROM lntmuser.[event]
INNER JOIN lntmuser.matter
ON lntmuser.matter.sysid = lntmuser.[event].mat_id
INNER JOIN lntmuser.matter2
ON lntmuser.matter2.sysid = lntmuser.[event].mat_id
WHERE DateDiff(month, Convert(date, CONVERT(CHAR,DATEADD(D, [event].[date], '1800-12-28'),101), 101), GETDATE()) = 1
GROUP BY replace(replace(replace([matter].client, 'P.C.', ''), 'PC', ''), 'INC', '')">
</asp:SqlDataSource>
基本上我想将值“conno”从外网格传递到内网格。我试过了
protected void RowBound(object sender, GridViewRowEventArgs e)
{
//string conno = ((DataBoundLiteralControl)e.Row.Cells[0].Controls[1]).Text;
//string conno = DataBinder.Eval(e.Row.DataItem, "con_no").ToString();
Session["conno"] = conno;
}
但这不是好事,这样做的正确方法是什么?感谢
答案 0 :(得分:1)
尝试以下方法(未经测试):将DataKeyNames
属性添加到外部gridView并将其设置为con_no
值。将嵌套sqldatasource的参数从SessionParameter更改为Parameter并重写RowBound
方法,如下所示:
protected void RowBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var innerrecs = e.Row.FindControl("innerrecs") as SqlDataSource;
innerrecs.SelectParameters["conno"].DefaultValue = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();
var gridView1 = e.Row.FindControl("GridView1") as GridView;
gridView1.DataBind();
}
}