如果我在此时输入文本框中的值,则显示输入值为重复的消息 [英] if i enter the value in textbox at that time display the message the enter value is duplicate

查看:96
本文介绍了如果我在此时输入文本框中的值,则显示输入值为重复的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助代码...我有一个文本框和一个标签...

help for that code...i have one textbox and one label their..

<body>
    <form id="form1" runat="server">
    <div>
        Customer Detail:-
        <br />
        <br />
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <table style="width: 80%">
            <tr>
                <td>
                    DC No:-
                </td>
                <td>
                    <asp:Label ID="lblDCNO" runat="server" Text="Label"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    Name:-
                </td>
                <td>
                    <asp:DropDownList ID="ddlstName" runat="server">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    Date:-
                </td>
                <td>
                    <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Chalan No:-
                </td>
                <td>
                    <asp:TextBox ID="txtChalan_No" runat="server"  ></asp:TextBox>
                    <asp:Label ID="lblMsg" runat="server" Text="Label" Visible="False"></asp:Label>
                </td>
            </tr>
        </table>
        <br />
        Order Detail:-<br />
        <table style="width: 100%">
            <tr>
                <td>
                    Sr. No:-
                </td>
                <td>
                    <asp:TextBox ID="txtSrno" runat="server"  ></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Iteam:-
                </td>
                <td>
                    <asp:DropDownList ID="ddlstItem" runat="server">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    Qty:-
                </td>
                <td>

                            <asp:TextBox ID="txtQty" runat="server" OnTextChanged="txtQty_TextChanged"   ></asp:TextBox>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"

                                ControlToValidate="txtQty" ErrorMessage="Only Numeric Value Allow"

                                ValidationExpression="^[0-9]"></asp:RegularExpressionValidator>

                </td>
            </tr>
            <tr>
                <td>
                    Rate:-
                </td>
                <td>

                            <asp:TextBox ID="txtRate" runat="server"  OnTextChanged="txtRate_TextChanged" AutoPostBack="true">
                            </asp:TextBox>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"

                                ControlToValidate="txtRate" ErrorMessage="Only Numeric Value Allow"

                                ValidationExpression="^[0-9]"></asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Amount:-
                </td>
                <td>
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <asp:TextBox ID="txtAmount" runat="server"  Enabled="false"  EnableTheming="True"></asp:TextBox>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
        </table>
        <br />
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="Button1_Click" />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

            onrowcancelingedit="GridView1_RowCancelingEdit"

            onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"

            onrowupdating="GridView1_RowUpdating"

            onrowdatabound="GridView1_RowDataBound" ShowFooter="true">
            <Columns>
                <asp:TemplateField HeaderText="SR_NO">
                    <ItemTemplate>
                        <asp:Label ID="lblSrno" runat="server" Text='<%# Eval("SR_NO") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Item">
                    <ItemTemplate>
                        <asp:Label ID="lblStcd" runat="server" Text='<%# Eval("ST_DESC") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlstItem1" runat="server">
                        </asp:DropDownList>
                        <asp:Label ID="lblStcd" runat="server" Text='<%# Eval("ST_DESC") %>'

                            Visible="false"></asp:Label>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="QTY">
                    <ItemTemplate>
                        <asp:Label ID="lblQty" runat="server" Text='<%# Eval("QTY") %>'></asp:Label>
                    </ItemTemplate>

                    <EditItemTemplate>
                        <asp:TextBox ID="txtQty1" runat="server"  AutoPostBack="true"

                            Text='<%# Eval("QTY") %>' ontextchanged="txtQty1_TextChanged"></asp:TextBox>
                    </EditItemTemplate>

                </asp:TemplateField>
                <asp:TemplateField HeaderText="RATE" FooterText="Total">
                    <ItemTemplate>
                        <asp:Label ID="lblRate" runat="server" Text='<%# Eval("RATE") %>'></asp:Label>
                    </ItemTemplate>

                    <EditItemTemplate>
                        <asp:TextBox ID="txtRate1" runat="server" Text='<%# Eval("RATE") %>'

                            ontextchanged="txtRate1_TextChanged" AutoPostBack="True"></asp:TextBox>
                    </EditItemTemplate>

                </asp:TemplateField>
                <asp:TemplateField HeaderText="AMT" >
                    <ItemTemplate>
                        <asp:Label ID="lblAmt" runat="server" Text='<%# Eval("AMT")%>'></asp:Label>
                    </ItemTemplate>

                    <EditItemTemplate>
                        <asp:TextBox ID="txtAmt1" runat="server" Enabled="False"

                            Text='<%# Eval("AMT")%>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="lblSum" runat="server"></asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>

                <asp:CommandField HeaderText="EDIT" ShowEditButton="True" ShowHeader="True" />
                <asp:CommandField HeaderText="DELETE" ShowDeleteButton="True"

                    ShowHeader="True" />

            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>







when i enter the value of chal no at thaat time check enter value is duplicate..




when i enter the value of chal no at thaat time check enter value is duplicate..

推荐答案

if you want to know that if the currently entered challan number exits in database or not then you may check the number of rows having the challan number as its entry i.e.

if you want to know that if the currently entered challan number exits in database or not then you may check the number of rows having the challan number as its entry i.e.
DataTable dt;
SqlCommand cmd = new SqlCommand("SELECT * FROM yourtablename WHERE ChallanNum=@challanNum");
SqlDataAdapter adap = new SqlDataAdapter(cmd, con);
adap.Fill(dt);

/*Check if dplicate value exists */
if(dt.rows.count>0)
{
MessageBox.Show("Challan Number Already Exists In Database");

}
else
{
 /*Insert your data */
}



Hope this solution has meet ur requirement


Hope this solution has meet ur requirement


See if you want to check the challan no. from your database then the above solution (solution 1) is good and you should do it on click event of Submit button of your form as the performance may slow down if you use the text_changed event of your text_box.



One piece of advice if you use the above mentioned code,

please use the query :



SELECT Count(*) FROM yourtablename WHERE ChallanNum=@challanNum;



as it will not fetch all the columns which are not required.



Count(*) will fetch only the number of rows matching the criteria.



Thanks \"bunzitop\" and hope this solution helps you \"hardikshah011\".
See if you want to check the challan no. from your database then the above solution (solution 1) is good and you should do it on click event of Submit button of your form as the performance may slow down if you use the text_changed event of your text_box.

One piece of advice if you use the above mentioned code,
please use the query :

SELECT Count(*) FROM yourtablename WHERE ChallanNum=@challanNum;

as it will not fetch all the columns which are not required.

Count(*) will fetch only the number of rows matching the criteria.

Thanks "bunzitop" and hope this solution helps you "hardikshah011".


这篇关于如果我在此时输入文本框中的值,则显示输入值为重复的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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