0

如果用户输入的注册号存在于数据库中,我正在尝试显示一个网格,如果注册号不存在,这意味着我还需要显示一个标签。我是 asp.net 中的一个新标签,所以请帮助我。下面是我的代码。

public DataTable madhrasaViewByRegNo(string viewByNo)
{
    try
    {
        madhrasaInfo infomadhrasa = new madhrasaInfo();
        object decobj = new object();
        if (sqlcon.State == ConnectionState.Closed)
        {
            sqlcon.Open();
        }
        SqlCommand sqlcmd = new SqlCommand("madhrasaViewByRegNo", sqlcon);
        sqlcmd.CommandType = CommandType.StoredProcedure;
        sqlcmd.Parameters.Add("@regNo", SqlDbType.VarChar).Value = viewByNo;
        decobj = sqlcmd.ExecuteNonQuery();
        if (decobj == null)
        {
            decStuId = decimal.Parse(decobj.ToString());
        }
        else
        {
            DataTable dtbClass = new DataTable();
            SqlDataAdapter sqlda = new SqlDataAdapter("madhrasaViewByRegNo", sqlcon);
            sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
            sqlda.SelectCommand.Parameters.Add("@regNo", SqlDbType.VarChar).Value = viewByNo;
            sqlda.Fill(dtbClass);
            return dtbClass;
        }
    }
    catch (Exception)
    {
        throw;
    }
    return null;
}
public void gridfillByNo()
{
    madhrasaSp spMadhrasa = new madhrasaSp();
    DataTable dtbl = new DataTable();
    dtbl = spMadhrasa.madhrasaViewByRegNo(TextBox2.Text);
    gvstuResult.DataSource = dtbl;
    gvstuResult.DataBind();
}
public void regSearch()
{
    madhrasaSp spmadhrasa = new madhrasaSp();
    spmadhrasa.madhrasaViewByRegNo(TextBox2.Text);
    if (madhrasaSp.decStuId > 0)
    {
        gridfillByNo();
        MultiView1.ActiveViewIndex = 1;
    }
    else
    {
        MultiView1.ActiveViewIndex = 0;
        Label1.Visible = true;
        Label1.Text = "Invalid Register Number";
    }
}
 protected void Button2_Click(object sender, EventArgs e)
 {
    regSearch();  
 }
4

2 回答 2

1

您不只是将网格视图的 EmptyDataText 设置为“Reg No Dosent exists”。它将解决您的问题。

于 2013-05-15T06:08:45.140 回答
0
<asp:GridView ID="GridView1" runat="server" EmptyDataText="register number not available">
</asp:GridView>
于 2013-05-15T07:35:12.293 回答