文本框应从数据库加载值 [英] The textbox should load the value from the database

查看:59
本文介绍了文本框应从数据库加载值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Ajax代码


 <   asp:ScriptManager     ID   ="     runat   =" 服务器" ">/ <   asp:UpdatePanel     ID   ="   runat   服务器"  UpdateMode   有条件的" <   ContentTemplate    <   asp:TextBox     ID   ="   runat   服务器" 
                     span>          ="   z-index:1;左侧:747px;顶部:180px;位置:绝对"  
 
                     span>          ="   TextBox23_TextChanged"  AutoPostBack   ="  >  <  /asp:TextBox  > 
        <  /ContentTemplate  > 
        <  触发器 > 
        <   asp:AsyncPostBackTrigger     ControlID   ="   EventName    TextChanged " / <  /触发器 > 



    <  /asp:UpdatePanel  >  




在我的代码文件中,我将断点保留在第1行上,如果文本更改了,请帮我解决.

 受保护的 无效 TextBox23_TextChanged(对象发​​件人,EventArgs e)//  loginID 
    {
        v_liginid = TextBox23.Text; // 第1行
        
    con.Open();
    SqlCommand cmd =  SqlCommand(" ,骗子);
    SqlParameter param =  SqlParameter();
    param.ParameterName = " ;
    param.Value = TextBox23.Text;
    cmd.Parameters.Add(param);
    SqlDataReader reader = cmd.ExecuteReader();
        如果(reader.HasRows)
    {
        Label55.Visible =  true ;
    }
    } 

解决方案

我不确定我是否理解您的问题,该事件不会触发吗?还是结果不正确/您期望什么?

如果是第二个原因,可能是因为您使用=而不是LIKE来检查liginid.如果用户尚未输入用户名(假设这是liginid是什么),则=将返回false,因为用户名"不等于"u",但是它是用户名"就像%u%".

如果仍然不能解决问题,请提供更多有关此问题的详细信息,我将尝试提供更多帮助.离开文本框.
添加另一个文本框,类型为TextBox23.Text,然后选择要添加的文本框


this is my ajax code


<asp:ScriptManager ID="ScriptManager1" runat="server" />


    <asp:UpdatePanel ID="UpdatePanel25" runat="server" UpdateMode="Conditional">


<ContentTemplate >
  <asp:TextBox ID="TextBox23" runat="server"

            style="z-index: 1; left: 747px; top: 180px; position: absolute"

            ontextchanged="TextBox23_TextChanged" AutoPostBack="True"></asp:TextBox>
        </ContentTemplate>
        <Triggers>
        <asp:AsyncPostBackTrigger ControlID="TextBox23" EventName="TextChanged" />
        </Triggers>



    </asp:UpdatePanel>




in my code file i kept the break point on line 1 , it should work if the text changed pls help me out.

protected void TextBox23_TextChanged(object sender, EventArgs e)   // loginID
    {
        v_liginid = TextBox23.Text; // line 1
        
    con.Open();
    SqlCommand cmd = new SqlCommand("select * from member where liginid = @v_liginid", con); 
    SqlParameter param = new SqlParameter();
    param.ParameterName = "@v_liginid"; 
    param.Value = TextBox23.Text; 
    cmd.Parameters.Add(param); 
    SqlDataReader reader = cmd.ExecuteReader(); 
        if (reader.HasRows) 
    {
        Label55.Visible=true;
    } 
    }

解决方案

I''m not sure I understand your question, is the event not firing? Or is the result not correct/what you expected?

If it''s the second one that might be because you check liginid with = instead of LIKE. If the user has not finished typing in his/her username (asuming that''s what liginid is) then = will return false, since ''username'' does not equal ''u'', however it ''username'' is LIKE ''%u%''.

If this doesn''t help, please give more details on the problem and I will try to help some more.


Even is now firing, because of after, when the text change client has to leave the textbox.
add another textbox type TextBox23.Text and select the textbox which is you added


这篇关于文本框应从数据库加载值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆