日期:2014-05-18  浏览次数:20925 次

c#地址传参求解
点击下一步,没有把参数传过去,麻烦大家帮忙看看,谢谢了

前台
HTML code

  <asp:TextBox ID="textfield" runat="server">请刷条码号</asp:TextBox>
    
    <asp:Button ID="Submit" runat="server" OnClick="Submit_Click" Text="搜索" />   
 
    
 <asp:FormView ID="FormView1" runat="server" Width="521px" Height="125px" >
        
<ItemTemplate>      

    您的姓名:<asp:Label ID="Label2" runat="server" Text='<%# Bind("brxm") %>'></asp:Label><br>
  
   您的联系方式:<asp:Label ID="Label3" runat="server" Text='<%# Bind("jtdh") %>'></asp:Label><br>
   <br><br><br><br><br><br><br>
<a href="javascript:location.href='ks.aspx?brxm=' + escape('<%=brxm%>') + '&jtdh=' + escape('<%=jtdh%>');void(0);">下一步</a>
  
  
          
</ItemTemplate>

</asp:FormView>





后台

C# code

public partial class _Default : System.Web.UI.Page
{   
    public string brxm;
    public string jtdh;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request.QueryString["brxm"] != null)//判断是否有接受值,如果有
        {
            brxm = Request.QueryString["brxm"].ToString();

        }
        if (Request.QueryString["jtdh"] != null)//判断是否有接受值,如果有
        {
            jtdh = Request.QueryString["jtdh"].ToString();

        }
        if (Request.QueryString["textfield"] != null)//判断是否有接受值,如果有
        {
            id = Request.QueryString["textfield"].ToString();
        }
        textfield.Attributes.Add("onclick", "if (this.value=='请刷条码号') this.value='';");


        textfield.Attributes.Add("onkeydown", "SubmitKeyClick('Submit');");


        //Link.Visible = false;


    }
   

    protected void Submit_Click(object sender, EventArgs e)
    {
        string ConnectionString = "server=192.168.1.20;Data Source=hrp;user id=hrp;password=hrp;";//写连接串

        OracleConnection conn = new OracleConnection(ConnectionString);//创建一个新连接

        try
        {
            conn.Open();

            OracleCommand cmd = conn.CreateCommand();

            cmd.CommandText = "select distinct brxm,jtdh from v_ms_brxx where jzkh like '%" + textfield.Text.ToString().Trim() + "%'";//sql查询语句


            OracleDataReader dr = cmd.ExecuteReader();


            FormView1.DataSource = dr;

            FormView1.DataBind();

       
            textfield.Text = "";


            textfield.Visible = false;

            Submit.Visible = false;


            dr.Close();
        
        }

        catch (Exception ee)
        {
            Response.Write(ee.Message); //如果有错误,输出错误信息
        }

        finally
        {
            conn.Close(); //关闭连接
        }

    }



}



------解决方案--------------------
<a href='ks.aspx?brxm=<%#Eval("brxm")%>&jtdh=<%#Eval("jtdh")%>'>下一步</a>