在 asp.net web 表单中通过 URL 提供输入

我正在使用 ASP.NET 上的 Web 服务,并且我有一个服务(该服务具有从数据库执行存储过程的代码,其中包含用户从表单中提供的参数)。 现在我有一个绑定到这个网络服务的网络表单,它工作得很好。 这是我的文件:

StudentService.cs

    public DataTable findStudent(string Index)
{
    string cs = Configurationmanager.ConnectionStrings["mycon"].ConnectionString;
    SqlConnection con = new SqlConnection(cs);
    SqlCommand cmd = new SqlCommand("oid_validation",con);
    cmd.CommandType = CommandType.StoredProcedure;
    SqlParameter parameter = new SqlParameter("@oid",Index);
    cmd.Parameters.Add(parameter);
    SqlDataAdapter da = new SqlDataAdapter();
    cmd.Connection = con;
    da.SelectCommand = cmd;
    DataTable dt1 = new DataTable();
    dt1.TableName = "audit.log";
    da.Fill(dt1);
    return dt1;
} 

表单.aspx

<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"/>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</form>

forms.cs

protected void Button1_Click(object sender,EventArgs e)
{

    string indexNr = TextBox1.Text;
    studentReference.studentServiceSoapClient service = new studentReference.studentServiceSoapClient();
    GridView1.DataSource = service.findStudent(indexNr);
    GridView1.DataBind();
    Guid g;
    if (Guid.TryParse(indexNr.ToString(),out g))
    { 
        Label1.Text = "Info: ";
        Label2.ForeColor = System.Drawing.Color.Green;
        Label2.Text = TextBox1.Text+ " is Guid";
    }
    else
    {
        Label1.Text = "Info: ";
        Label2.ForeColor = System.Drawing.Color.Red;
        Label2.Text = TextBox1.Text + " is Not Guid";
    }
}

这一切正常,但我想要做的是从 forms.aspx 中删除那个文本框和按钮,只允许用户通过 URL 输入参数,例如:

http://localhost:54092/Default.aspx?MyParameter=13451 当用户点击 go 或 enter 时,它会被执行并且数据会出现在我的 gridview 上; 顺便说一句,我是 asp.net 和 Web 服务的新手,如果我的问题听起来很傻或者我的代码没有以完美的方式编写,请原谅我

zbrabbit 回答:在 asp.net web 表单中通过 URL 提供输入

在 WebForms 页面上,您可以像这样访问查询字符串:

string guid = Request.QueryString["guid"];
本文链接:https://www.f2er.com/29290.html

大家都在问