当我进入页面时,我可以毫无问题地获取所有数据我的sql正常工作但是当我进入页面时它会出错(第一个下拉列表值为0):
“TemplateField不支持回调,因为有些控件 无法在回调中正确更新。关闭回调 'GridView1'。“
Page Load c#3:
if (!IsPostBack)
{
DBConnection db=new DBConnection();
ArrayList listdrp = new ArrayList();
ArrayList listurl = new ArrayList();
listdrp.Insert(0, "SharedItems");
listdrp.Insert(1, "SyndicationItems");
listdrp.Insert(2, "All Items");
DropDownList1.DataSource = listdrp;
DropDownList1.DataBind();
GridView1.DataSource = db.getGroupRSS( groupName, DropDownList1.SelectedIndex);
GridView1.DataBind();
}
//sql side
public DataSet getGroupRSS( string name, int drpIndex)
{
string sql="";
if (drpIndex == 0)
{
//SQL string to count the amount of rows within the OSDE_Users table
sql = "SELECT [RSS_Title], [RSS_ID], R.Syndication, R.Category FROM RSS AS R INNER JOIN Group_URL AS F ON F.URL= R.URL Where F.Group_Name='"+name+"' ORDER BY RSS_Date desc";
// string sql = "SELECT [RSS_Title], [RSS_ID], R.Syndication, R.Category FROM RSS AS R INNER JOIN CombinedFeeds AS C ON C.URL = R.URL WHERE C.Name='" + name + " ' ORDER BY RSS_Date desc";
}
else if (drpIndex == 1)
{
sql = "SELECT [RSS_Title], R.RSS_ID, R.Syndication, R.Category FROM RSS AS R INNER JOIN Group_Shared_Items AS F ON F.RSS_ID= R.RSS_ID Where F.Group_Name='" + name + "' ORDER BY RSS_Date desc";
}
SqlDataAdapter adapt = new SqlDataAdapter(sql, Connect());
DataSet ds = new DataSet();
adapt.Fill(ds);
// result of query filled into datasource
adapt.Dispose();
closeConnection();
return ds;
}
客户端
}
<li> <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Logout</asp:LinkButton> </li>
</ul>
<table>
<tr>
<td>
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True" Height="16px" Width="88px">
</asp:DropDownList>
</td>
</tr>
</table>
</div>
<div id="center-column">
<div class="top-bar">
<h1 align="center">My Groups' Items</h1>
</div><br />
<br />
<div>
<br />
<br />
<table width="100%">
<tr>
<td align='center'>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
onselectedindexchanged="GridView1_SelectedIndexChanged" PageSize="8"
AutoGenerateColumns="False" onrowcommand="GridView1_RowCommand"
onrowcreated="GridView1_RowCreated" EnableSortingAndPagingCallbacks="True"
CellPadding="4" ForeColor="#333333" GridLines="None"
onpageindexchanging="GridView1_PageIndexChanging">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:ButtonField CommandName="AddComment" ButtonType="Image" HeaderText="Comment"
ImageUrl="~/images/commentt.png" Text="Comment"
ItemStyle-HorizontalAlign="Center" >
<asp:ButtonField CommandName="Share" ButtonType="Image" HeaderText="Share with Friends"
ImageUrl="~/images/openshare.png" ItemStyle-HorizontalAlign="Center"
Text="Share" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
<asp:ButtonField CommandName="ShareGroups" ButtonType="Image" HeaderText="Share with Groups"
ImageUrl="~/images/Group.png" ItemStyle-HorizontalAlign="Center"
Text="Share" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
<asp:ButtonField ButtonType="Image" HeaderText="Favorites"
ImageUrl="~/images/StarEmpty.png" CommandName="Favorite"
Text="Add to Favorites" ItemStyle-HorizontalAlign="Center">
<FooterStyle Height="20px" />
<HeaderStyle Width="3px" />
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
<asp:ButtonField ButtonType="Image" CommandName="Mail" HeaderText="Send Mail"
ImageUrl="~/images/email-icon.png.jpg" Text="Send Mail"
ItemStyle-HorizontalAlign="Center" InsertVisible="False" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
<asp:TemplateField HeaderText="RSS Title">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="View" Font-Size="Small" Font-Underline="False"><%#Eval("RSS_Title") %></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="Syndication" HeaderText="Syndication"
SortExpression="Syndication" />
<asp:BoundField DataField="Category" HeaderText="Category"
SortExpression="Category" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
</td>
</tr>
</table>
<br />
答案 0 :(得分:4)
你需要传呼吗?如果没有设置EnableSortingAndPagingCallbacks = false
。如果这没有帮助,您可能还需要发布您的html标记。
答案 1 :(得分:3)
请参阅此网址 - &gt;
All columns in the Columns collection must support callbacks for this feature to work. If the Columns collection contains a column that does not support callbacks, such as TemplateField, a NotSupportedException exception is raised.