リストに2つのアイテムを追加すると、詳細ビューのリストから最初に更新されたアイテムしか表示できないため、リストに10個のアイテムがある場合、すべてのアイテムにタイトルを表示する必要があります。各ハイパーリンクボタンに、id からそのタイトルに関する情報を表示したい
ここに私がやりたいことの画像リンクがあります。 http://i.stack.imgur.com/ZhJmc.jpg
protected void ButtonChoose_Click(object sender, EventArgs e)
{
try
{
if (DropDownListNewsFeed.SelectedItem.Value == "All")
{
SPWeb web = SPContext.Current.Web;
SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = "<Lists>" +
"<List ID=" + web.Lists.TryGetList("Staff News").ID.ToString() + " />" +
"<List ID=" + web.Lists.TryGetList("Company News").ID.ToString() + " />" +
"<List ID=" + web.Lists.TryGetList("Management News").ID.ToString() + " />" +
"</Lists>";
query.ViewFields = "<FieldRef Name=\"Title\" /><FieldRef Name=\"Date1\" Nullable=\"TRUE\"/>";
query.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE'></FieldRef></OrderBy>";
query.Webs = "<Webs Scope=\"SiteCollection\" />";
query.RowLimit = 10;
DataTable dt = web.GetSiteData(query);
DataView dv = new DataView(dt);
GridViewNewsFeed.DataSource = dv;
GridViewNewsFeed.DataBind();
}
else if(DropDownListNewsFeed.SelectedItem.Value == "Staff News")
{
SPWeb web = SPContext.Current.Web;
SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = "<Lists><List ID=" + web.Lists.TryGetList("Staff News").ID.ToString() + " /></Lists>";
query.ViewFields = "<FieldRef Name=\"Title\" /><FieldRef Name=\"Date1\" Nullable=\"TRUE\"/>";
query.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE'></FieldRef></OrderBy>";
query.Webs = "<Webs Scope=\"SiteCollection\" />";
query.RowLimit = 10;
DataTable dt = web.GetSiteData(query);
DataView dv = new DataView(dt);
GridViewNewsFeed.DataSource = dv;
GridViewNewsFeed.DataBind();
}
else if (DropDownListNewsFeed.SelectedItem.Value == "Management News")
{
SPWeb web = SPContext.Current.Web;
SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = "<Lists><List ID=" + web.Lists.TryGetList("Management News").ID.ToString() + " /></Lists>";
query.ViewFields = "<FieldRef Name=\"Title\" /><FieldRef Name=\"Date1\" Nullable=\"TRUE\"/>";
query.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE'></FieldRef></OrderBy>";
query.Webs = "<Webs Scope=\"SiteCollection\" />";
query.RowLimit = 10;
DataTable dt = web.GetSiteData(query);
DataView dv = new DataView(dt);
GridViewNewsFeed.DataSource = dv;
GridViewNewsFeed.DataBind();
}
else if (DropDownListNewsFeed.SelectedItem.Value == "Company News")
{
SPWeb web = SPContext.Current.Web;
SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = "<Lists><List ID=" + web.Lists.TryGetList("Company News").ID.ToString() + " /></Lists>";
query.ViewFields = "<FieldRef Name=\"Title\" /><FieldRef Name=\"Date1\" Nullable=\"TRUE\"/>";
query.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE'></FieldRef></OrderBy>";
query.Webs = "<Webs Scope=\"SiteCollection\" />";
query.RowLimit = 10;
DataTable dt = web.GetSiteData(query);
DataView dv = new DataView(dt);
GridViewNewsFeed.DataSource = dv;
GridViewNewsFeed.DataBind();
}
}
catch (Exception x)
{
LabelException.Text = x.Message;
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
try
{
SPWeb web = SPContext.Current.Web;
SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = "<Lists>" +
"<List ID=" + web.Lists.TryGetList("Staff News").ID.ToString() + " />" +
"<List ID=" + web.Lists.TryGetList("Company News").ID.ToString() + " />" +
"<List ID=" + web.Lists.TryGetList("Management News").ID.ToString() + " />" +
"</Lists>";
query.ViewFields = "<FieldRef Name=\"Title\" />" +
"<FieldRef Name=\"Authors\" />" +
"<FieldRef Name=\"Link\" />" +
"<FieldRef Name=\"Contents\" />" +
"<FieldRef Name=\"_Category\" />" +
"<FieldRef Name=\"Date1\" Nullable=\"TRUE\"/>";
//query.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE'></FieldRef></OrderBy>";
query.Webs = "<Webs Scope=\"SiteCollection\" />";
query.RowLimit = 10;
DataTable dt = web.GetSiteData(query);
DataView dv = new DataView(dt);
DetailsViewShowNews.DataSource = dv;
DetailsViewShowNews.DataBind();
}
catch (Exception x)
{
LabelException.Text = x.Message;
}
}
これは私のasp gridviewコードです:
<asp:GridView AutoGenerateColumns="False" ID="GridViewNewsFeed" runat="server" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="Solid" BorderWidth="1px" CellPadding="4"
EnableModelValidation="True" GridLines="Vertical" ForeColor="Black" >
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" OnClick="LinkButton1_Click" runat="server" Text='<%# Bind("Title") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:templatefield headertext="Date">
<itemtemplate>
<asp:label id="lblDate" runat="server" text='<%# DateTime.Parse(Eval("Date1").ToString()).ToString("d") %>' />
</itemtemplate>
</asp:templatefield>
</Columns>
</asp:GridView>
これは私のASP詳細表示コードです:
<asp:DetailsView AutoGenerateRows="False" ID="DetailsViewShowNews" runat="server"
BackColor="White" BorderColor="#336666" BorderWidth="1px"
CellPadding="4" EnableModelValidation="True" GridLines="Horizontal"
Height="226px" Width="301px" BorderStyle="Solid" >
<EditRowStyle BackColor="#339966" ForeColor="White" Font-Bold="True" />
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White"
HorizontalAlign="Center" />
<Fields>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%#Eval("Title") %>' Font-Size="Large" Font-Bold="True"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox22" runat="server" Text='<%#Eval("Contents") %>' TextMode="MultiLine" Height="100%" BorderStyle="None" ReadOnly="True" Width="250px" style="overflow:auto;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label72" runat="server" Text='<%#Eval("_Category") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label52" runat="server" Text='<%#Eval("Authors") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label32" runat="server" Text='<%#DateTime.Parse(Eval("Date1").ToString()).ToString("d") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<a href="<%#Eval("Link") %>"><asp:Label ID="Label42" runat="server" Text='<%#Eval("Link") %>' ></asp:Label> </a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButtonComment" OnClick="LinkButtonComment_Click" runat="server">Leave a comment</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Fields>
<RowStyle BackColor="White" ForeColor="#333333" />
</asp:DetailsView>