[英]Gridview Item Template Pass Value from Outer Grid to Inner Grid
I'm trying to nest two Grid_Views like ... 我正在尝试嵌套两个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>
Basically I want to pass the value "conno" from the Outer Grid to the Inner Grid. 基本上,我想将值“ conno”从外部网格传递到内部网格。 I tried 我试过了
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;
}
But this is no good, what is the correct way to do this ?. 但这不好,正确的方法是什么? Thanks 谢谢
Try following approach (not tested): add DataKeyNames
property to the outer gridView and set it to con_no
value. 尝试以下方法(未经测试):将DataKeyNames
属性添加到外部gridView并将其设置为con_no
值。 Change parameter for nested sqldatasource from SessionParameter to Parameter and rewrite RowBound
method as below: 将嵌套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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.