会话方法的模糊值转移中继器

时间:2014-11-17 08:49:10

标签: c# asp.net repeater

我正在尝试通过转发器按钮控件单击将值从一个页面传输到另一个页面。 OnLoad它将正确的TID传输到下一页,但点击按钮“印度”它给下一页错误的TID。

数据库场景是: 数据库名称“测试” 表名:“ConDet”

Table Structure:

TID     Location    CountryName

1001    Mumbai      India

1002    Delhi       India

1003    New York    USA

1004    Tokyo       Japan

主页设计:

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <table><tr><td>
        <asp:Button ID="Ind"  runat="server" Text="India" OnClick="Ind_Click"/>
    </td><td>
        <asp:Button ID="usa"  runat="server" Text="USA"/>

    </td><td>
        <asp:Button ID="jap"  runat="server" Text="Japan"/>

    </td></tr></table>

    <asp:Repeater ID="rep" runat="server" OnItemCommand="RepeaterClick" >
        <ItemTemplate >
            <table><tr><td>
                <asp:Label ID="ConCode" runat="server"  Text='<%#Eval("TID") %>'></asp:Label>
            </td><td>
                <asp:Label ID="loc" runat="server"  Text='<%#Eval("Location") %>'></asp:Label>

            </td><td>
                <asp:Label ID="Country" runat="server"  Text='<%#Eval("CountryName") %>'></asp:Label>
            </td></tr><tr><td>
               <asp:Button ID="inpt" runat="server"  Text="Contect"  CommandName="contact" UseSubmitBehavior="false"/>
            </td></tr></table>
        </ItemTemplate>
    </asp:Repeater>    
</form>

代码背后:

    protected void Page_Load(object sender, EventArgs e)
    {
        DBind();
    }

    public void DBind() 
    {
        string sqlconstr = ConfigurationManager.AppSettings["Mystring"];
        SqlConnection con = new SqlConnection(sqlconstr);
        con.Open();

        string sql = "select * from ConDet order by TID desc";
        SqlCommand cmd = new SqlCommand(sql, con);
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        rep.DataSource = ds;
        rep.DataBind();


    }

    protected void RepeaterClick(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "contact")
        {

            Label srk = (Label)e.Item.FindControl("ConCode");
            Session["PID"] = srk.Text;
            Server.Transfer("Test.aspx");

        }
    }

    protected void Ind_Click(object sender, EventArgs e)
    {
        string sqlconstr = ConfigurationManager.AppSettings["Mystring"];
        SqlConnection con = new SqlConnection(sqlconstr);
        con.Open();

        string sql = "select * from ConDet where CountryName='India' order by TID desc";
        SqlCommand cmd = new SqlCommand(sql, con);
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        rep.DataSource = ds;
        rep.DataBind();

    }

下一页名称:测试页

 <form id="form1" runat="server">
    <asp:Label ID="CCode" runat="server"></asp:Label>
</form>

代码背后:

 protected void Page_Load(object sender, EventArgs e)
    {
        CCode.Text = Session["PID"].ToString();
    }

我正在尝试将TID转移到另一个页面“Test”上,加载事件运行良好。它允许我将正确的TID传输到下一页“测试”,但是当我尝试按点击按钮(text =“India”)加载新数据时,它会给下一页名称“测试”提供错误的TID 哪里错了?如何解决它以在任何订单上获得正确的TID转移到下一页?。

0 个答案:

没有答案