如果在我的列表中添加这两个项目,我只能在详细信息视图中显示列表中的第一个更新项目,所以我的问题是,如果我在列表中有 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 detailsview 代码:
<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>