试图在InsertItemTemplate中找到一个文本框控件

时间:2016-05-04 13:40:36

标签: c# asp.net listview

我目前正在尝试在InsertItemTemplate中找到一个文本框控件来测试我的某个数据库表中的值,但我似乎无法让FindControl工作。以下是我目前正在查看的代码:

    protected void InsertButton_Click(object sender, EventArgs e)
{

    TextBox linkinsTextBox = Page.FindControl("linkinsTextBox") as TextBox;
    String connectionString = WebConfigurationManager.ConnectionStrings["UniString"].ConnectionString;
    SqlConnection myConnection = new SqlConnection(connectionString);

    myConnection.Open();

    bool exists = false;

    //The number of entries in links is counted
    String linkCountQuery = " SELECT COUNT(link) from[links] where link = " + linkinsTextBox.Text + "";

    SqlCommand linkCountQueryCommand = new SqlCommand(linkCountQuery, myConnection);
    Int32 linkCountQueryCommandValue = (Int32)linkCountQueryCommand.ExecuteScalar();
    myConnection.Close();

    if (linkCountQueryCommandValue >= 1)
    {
        exists = true;
        URLexists.Text = "URL already exists. Please enter a different URL.";
    }

}

0 个答案:

没有答案