开发者

Problem with GridViewControl

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
    <asp:GridView ID="GridView1" runat="server" Height="464px" Width="743px" 
        AutoGenerateColumns="False" EmptyDataText="No Rows Selected" 
        DataSourceID="Answered" 

        style="z-index: 1; left: 327px; top: 334px; position: absolute; height: 464px; width: 743px">
        <Columns>
            <asp:BoundField DataField="ThreadTitle" HeaderText="ThreadTitle" 
                SortExpression="ThreadTitle" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="Answered" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CP_AllQuestionsAnswered %>" SelectCommand="SELECT ThreadTitle
FROM Threads AS t
INNER JOIN Users AS u ON  t.UsersID=u.UsersID
WHERE t.UsersID=@UserID">
        <SelectParameters>
            <asp:Parameter Name="UserID" />
        </SelectParameters>
    </asp:SqlDataSource>
  </div>
</asp:Content>

Code File:

protected void Page_Load(object sender, EventArgs e)
{
    Membershi开发者_JS百科pUser CurrentUser = Membership.GetUser();
    Guid userid = (Guid)CurrentUser.ProviderUserKey;
    Answered.SelectParameters.Add("UserID", userid.ToString().Trim());
}

When I modify the grid's datasource, I write my query and test it with a specific grid and it gives me the expected results. But when I run the grid view, all I get is "Empty rows". Why is that?!?


My guess is this: in your Page_Load, you're constantly adding a new parameter to your SQL datasource, even though that parameter is already defined.

Try this instead - setting the value of the existing parameter:

protected void Page_Load(object sender, EventArgs e)
{
   MembershipUser CurrentUser = Membership.GetUser();
   Guid userid = (Guid)CurrentUser.ProviderUserKey;
   Answered.SelectParameters["UserID"].DefaultValue = userid.ToString().Trim();
}

Does that change anything?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜