本文介绍了如何禁用文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我有两个文本框和一个图像按钮。如果我在两个文本框中输入内容,我将单击图像按钮搜索数据库中的现有记录(SQL SERVER 2008-R2),并将显示在我的网格视图中。它对我工作正常但我有一个要求,搜索后它找到一个匹配两个文本框的记录,显示记录到网格视图,两个文本框将被禁用。但如果没有找到记录,两个文本框将保持启用状态。现在的问题是我不知道该怎么做。请帮助我:)

Hi guys!
I have two text boxes and an image button. If I input something to both text boxes, I will click the Image button to search for the existing record in my database (SQL SERVER 2008-R2) and will display at my grid view. It works fine to me BUT I have a requirement that after searching and it find a record that matches the two text boxes,display the record to grid view and the two text boxes will be disabled.But if no records found, the two text boxes will remain as enabled. The problem now is that I do not know on how to do that. Please help me :)

推荐答案

if(txt1.Text!="" && txt2.Text!="")
{
    DataSet ds=new Dataset();
    ds=//Put data into dataset.
    if(ds.Tables[0].Rows.Count>0)
    {
        // Bind your grid here..
        // Disable your Textbox1 and Textbox2
        txt1.Enabled=false;
        txt2.Enabled=false;
    }

}


gridView1.Rows.Count()



然后,如果行数> 0,则需要禁用文本框。




Then if row count >0 you need to disable text boxes.

TextBox.Enabled = false



这篇关于如何禁用文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 04:45