0

ページに入ると、問題なくすべてのデータを取得できますが、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&#39; 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 />
4

2 に答える 2

4

ページングが必要ですか?設定されていない場合EnableSortingAndPagingCallbacks = false。これで問題が解決しない場合は、HTMLマークアップも投稿する必要があります。

于 2012-04-27T13:29:39.710 に答える
3

このURLをご覧ください->

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.enablesortingandpagingcallbacks(v=vs.80).aspx

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.
于 2012-04-27T13:33:51.993 に答える