我在aspxgridview
上有详细问题。当所有详细信息行都展开并且我单击任何详细信息行时; PublicationClickCallback
功能仅对最后一个细节网格有效。
我会很感激能够帮助我实现目标。
我提到了下面的表格和代码
致谢
我的桌子:
CREATE TABLE Table_1(
T1_Id int IDENTITY(1,1) PRIMARY KEY ,
T1_Title varchar(20)
)
GO
CREATE TABLE Table_2(
T1_Id int ,
T2_Id int IDENTITY(1,1),
T2_Title varchar(20) ,
PRIMARY KEY (T1_Id ASC, T2_Id ASC) ,
FOREIGN KEY(T1_Id) REFERENCES Table_1 (T1_Id) ON UPDATE CASCADE ON DELETE CASCADE
)
GO
insert into Table_1 (T1_Title) values ('a'),('b'),('c')
insert into Table_2 (T1_Id,T2_Title) values (1,'a1'),(1,'a2'),(1,'a3')
insert into Table_2 (T1_Id,T2_Title) values (2,'b1'),(2,'b2'),(2,'b3')
insert into Table_2 (T1_Id,T2_Title) values (3,'c1'),(3,'c2'),(3,'c3')
我的html代码:
<script type="text/javascript">
function PublicationClickCallback(values) {
var dRow = values;
var filterExpression = "T2_Title='" + dRow + "'";
ASPxGridView2.ApplyFilter(filterExpression);
isFiltered = true;
}
</script>
<dx:ASPxGridView ID="ASPxGridView1" ClientInstanceName="ASPxGridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="T1_Id"
OnDataBound="ASPxGridView1_DataBound" Width="30%">
<ClientSideEvents RowClick="function(s, e){ s.ExpandDetailRow(e.visibleIndex); }" />
<SettingsDetail ShowDetailRow="True" ShowDetailButtons="False" />
<Templates>
<DetailRow>
<dx:ASPxGridView ID="ASPxGridView2" ClientInstanceName="ASPxGridView2" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource2" KeyFieldName="T1_Id"
Width="100%" OnBeforePerformDataSelect="ASPxGridView2_BeforePerformDataSelect">
<ClientSideEvents RowClick="function(s, e) {
s.GetRowKey(e.visibleIndex);
s.GetRowValues(e.visibleIndex, 'T2_Title', PublicationClickCallback);
}" />
<Columns>
<dx:GridViewDataTextColumn FieldName="T1_Id" ReadOnly="True" VisibleIndex="0">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="T2_Id" ReadOnly="True" VisibleIndex="1">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="T2_Title" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
<Settings ShowColumnHeaders="False" />
</dx:ASPxGridView>
</DetailRow>
</Templates>
<Settings ShowColumnHeaders="False" />
<Columns>
<dx:GridViewDataTextColumn FieldName="T1_Id" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="T1_Title" VisibleIndex="1">
</dx:GridViewDataTextColumn>
</Columns>
<Styles>
<Row BackColor="#99CCFF" Font-Bold="True" ForeColor="Black">
</Row>
</Styles>
</dx:ASPxGridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RoniaConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:RoniaConnectionString1.ProviderName %>" SelectCommand="SELECT [T1_Id], [T1_Title] FROM [Table_1]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:RoniaConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:RoniaConnectionString1.ProviderName %>" SelectCommand="select * from Table_2 where T1_Id = @T1_Id ">
<SelectParameters>
<asp:SessionParameter Name="T1_Id" SessionField="T1_Id" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="T2_Title" Type="String" />
<asp:Parameter Name="T1_Id" Type="Int32" />
<asp:Parameter Name="T2_Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
我的代码:
protected void ASPxGridView2_BeforePerformDataSelect(object sender, EventArgs e)
{
Session["T1_Id"] = (sender as ASPxGridView).GetMasterRowKeyValue().ToString();
}
protected void ASPxGridView1_DataBound(object sender, EventArgs e)
{
((ASPxGridView)sender).DetailRows.ExpandAllRows();
}