1

I've been having troubles getting my textbox to refresh a GridView from the onchange event.

The GridView is linked up to a LINQ data source and the LINQ data source has a Where Parameter UserId that it gets from the textbox... Here's the code:

    <asp:Label ID="label_UserId" runat="server" Text="Search by User Id: "></asp:Label>
    <asp:TextBox ID="textbox_UserId" Text="12" runat="server" 
        ontextchanged="textbox_UserId_TextChanged"></asp:TextBox>

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="UserID" DataSourceID="LINQUserSource" 
        EmptyDataText="There are no data records to display.">
        <Columns>
            <asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True" 
                SortExpression="UserID" />
            <asp:BoundField DataField="Username" HeaderText="Username" 
                SortExpression="Username" />
            <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                SortExpression="FirstName" />
            <asp:BoundField DataField="LastName" HeaderText="LastName" 
                SortExpression="LastName" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
        </Columns>
    </asp:GridView>

    <asp:LinqDataSource ID="LINQUserSource" runat="server" 
        ContextTypeName="DotNetNuke.Modules.Report.UsersDataContext" 
        Select="new (UserID, Username, FirstName, LastName, Email)" Where="UserId = @UserId"
        TableName="Users">
        <WhereParameters>
            <asp:ControlParameter
                Name="UserId"
                DefaultValue="0"
                ControlID="textbox_UserId"
                Type="Int32" /> 
        </WhereParameters>
    </asp:LinqDataSource>

So far I have nothing for the backend code. Since I set the textbox to be 12 by default, the GridView loads with the record of UserId 12, but now I want the GridView to reload if I change the number in the textbox. Any ideas?

4

4 回答 4

5

首先将 AutoPostBack 属性添加到您的文本框:

<asp:TextBox ID="textbox_UserId" Text="12" runat="server" 
    AutoPostBack="true" ontextchanged="textbox_UserId_TextChanged"/>

然后,把它放在你的代码后面:

protected void textbox_UserId_TextChanged(object sender, EventArgs e)
{
    GridView1.DataBind();
}
于 2009-07-29T02:17:23.720 回答
2

打电话

GridView1.DataBind();

输入新值后。

于 2009-07-28T21:25:30.300 回答
0
OleDbCommand cmd = new OleDbCommand("update ESInfo1 set OrdTime='" + td.ToString() + "', SSO2='" + DropSupportOfficer.Text + "', Orderby='" + Txthst.Text + "' where Sln=" + Txtsln.Text + "", con);
cmd.ExecuteNonQuery();
GridView1.DataBind();
cmd.Dispose()

但gridview中没有行

于 2012-01-18T05:26:22.433 回答
-1

创建一个数据表方法并返回

GridView1.DataSource = 方法();GridView1.DataBind();

于 2012-03-26T13:18:30.260 回答