각 GridView는 이전에 종속적 인 세 개의 GridView를 중첩합니다. asp 구조를 완료하고 각 각 해당 데이터 원본 (asp : aspx 페이지에서 SqlDataSource) 당기는 것입니다. 그러나 관계를 구축하는 방법을 알아낼 수 없으므로 각각은 격자가 중첩 된 행과 관련된 데이터 만 가져옵니다.부모에서 자식으로 매개 변수 전달 ASP GridView (C# 코드 숨김)
예 : Similar but I don't need the drill downs
Also very like what I'm looking for but this uses EntityDataSource
이러한 예는 내가이 일을 할 수있는 RowDataBound 이벤트가 필요합니다 이해하는 저를 도왔다. 큰! 하지만 RowDataBound 이벤트를 통해 다음 GridView에서 데이터를 생성하는 데이터 소스를 통해 실행해야하는 행마다 고유 한 매개 변수를 제공하는 방법을 파악할 수 없습니다.
Codebehind가 : 여기
protected void CategoryGrid_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
//need to set my @catlinkulink parameter here
}
protected void CategoryGrid_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void CategoryOnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView CategoryGridFC = DomainGrid.Rows[e.Row.RowIndex].FindControl("CategoryGrid") as GridView;
string catlinkulink = CategoryGridFC.DataKeys[e.Row.RowIndex].Values["catlinkulink"].ToString();
TargetLinks.SelectParameters[0].DefaultValue = catlinkulink;
}
}
는 영문의 데이터 소스이다. 이전에 범주 그리드의 각 행에서 가져온 매개 변수에 따라 달라지는 모눈에 대한 것입니다.
<asp:SqlDataSource ID="TargetLinks" runat="server"
ConnectionString="<%$ ConnectionStrings:MyDB %>"
SelectCommand="SELECT t.ULink AS targetlinkulink, TargetDE
FROM targetLink t
INNER JOIN IntTargets it ON t.TargetULink = it.ULink
INNER JOIN IntCategoryLink cl ON t.CatLinkULink = cl.ULink
WHERE t.CatLinkULink = @catlinkulink"
>
<SelectParameters>
<asp:Parameter Name="catlinkulink" DefaultValue="0" Type="Empty" Size="0" ConvertEmptyStringToNull="False" DbType="Object" />
</SelectParameters>
</asp:SqlDataSource>
나는이게 얼마나 오랫동안 죄송하지만 난 내가 할 노력하고있어 명확한 아이디어를 제공 할 수있는 충분한 정보를 제공 있는지 확인하려면. 당신이 가지고있는 모든 의견에 감사드립니다. 나는 뭔가를 성취하기 위해 다른 방법이나 더 나은 방법이라 할지라도 항상 많이 배웁니다.
다음 제안 사항에 따라 TargetLinks 비트를 추가했습니다. CategoryGrid의 FindControl을 변경하여 DomainGrid (부모)의 행을 살펴 보았지만 작동하지 않습니다.
Error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
다음은 중첩 된 GridView의 코드입니다.
<asp:GridView ID="DomainGrid" runat="server"
onselectedindexchanged="DomainGrid_SelectedIndexChanged"
DataSourceID="DomainLinks" AutoGenerateColumns="False" DataKeyNames="domainlinkulink">
<Columns>
<asp:BoundField DataField="DomainDE" ShowHeader="False"
SortExpression="DomainDE" HeaderStyle-Width="125">
</asp:BoundField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:DropDownList ID="IntervCatDrop" runat="server" DataSourceID="IntervCatDD"
DataValueField="ulink" DataTextField="IntCategories">
</asp:DropDownList> <asp:Button ID="AddIntCat" runat="server" Text="+" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:GridView ID="CategoryGrid" runat="server" DataKeyNames="catlinkulink"
DataSourceID="IntCategoryLinks" AutoGenerateColumns="false"
onselectedindexchanged="CategoryGrid_SelectedIndexChanged"
onrowdatabound="CategoryOnRowDataBound">
<Columns>
<asp:BoundField DataField="IntCategories" ShowHeader="False"
SortExpression="Categories" HeaderStyle-Width="125"></asp:BoundField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:DropDownList ID="TargetDrop" runat="server" DataSourceID="TargetsDD"
DataValueField="ulink" DataTextField="TargetDE">
</asp:DropDownList> <asp:Button ID="AddTarget" runat="server" Text="+" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<asp:GridView ID="TargetGrid" runat="server" DataSourceID="TargetLinks" AutoGenerateColumns="False"
DataKeyNames="targetlinkulink" onselectedindexchanged="TargetGrid_SelectedIndexChanged"
>
<Columns>
<asp:BoundField DataField="TargetDE" ShowHeader="false" SortExpression="TargetDE" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
행 바인딩 이벤트에서 asp : 매개 변수 값을 다음과 같이 설정하십시오. TargetLinks.SelectParameters [0] .DefaultValue = catlinkulink; – PushCode
고마워요! 나는 그것을 추가했다. –
@R_Scott - 당신이 얻고있는 오류는 무엇입니까, 방금 코멘트에 코드를 올렸습니까? –