开发者

Search by name and id in asp.net

开发者 https://www.devze.com 2023-03-10 18:10 出处:网络
I have to search on form with id and name also in asp.net, what condition should i use to check the user is enteredid in text box id field or text box for name or should i use only 1 textbox for sear

I have to search on form with id and name also in asp.net,

what condition should i use to check the user is entered id in text box id field or text box for name or should i use only 1 textbox for search by开发者_如何学运维 id and name too..

m using sql server 2005 for storing records.

thank u


On your ASP.Net page, you can use a RequiredFieldValidator to make sure that the user has entered something in the textbox.

<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter your user name." ControlToValidate="UserNameTextBox" Display="Dynamic" />

I would use one textbox and let the user enter either their username or ID.

Then you write a query on the database to SELECT COUNT(*) FROM Users WHERE (UserName = @UserName) OR (UserID = @UserID). Something like that. If COUNT equals zero, there was no match. If COUNT is greater than zero, you have a match.


Use a combo box with two values: ID, Name

Then when user types in textbox, you can check the value selected in combobox, to know whether he is searching by Id or Name

0

精彩评论

暂无评论...
验证码 换一张
取 消