i have 5 textbox one search button

Posted by Kranthi under ASP.NET on 11/10/2010 | Points: 10 | Views : 2097 | Status : [Member] | Replies : 15
I have 7 textbox one search button this search button should be mendatory for anyone textbox should be entered then only the search result will be displayed and this program will write using javascript




Responses

Posted by: Vuyiswamb on: 11/10/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
I thought i helped you with your problem

Thank you for posting at Dotnetfunda
[Administrator]

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kranthi on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
yes sure but my concept is when user give input in anyone textbox then the result will be displayed not require all textbox should be.

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhuk on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
<script type="text/javascript">

function GetElemets()
{
var text1 = document.getElementById('<%=TextBox1.ClientID%>').value;
var text2 = document.getElementById('<%=TextBox2.ClientID%>').value;
var text3 = document.getElementById('<%=TextBox3.ClientID%>').value;
var text4 = document.getElementById('<%=TextBox4.ClientID%>').value;
var text5 = document.getElementById('<%=TextBox5.ClientID%>').value;
var text6 = document.getElementById('<%=TextBox5.ClientID%>').value;
var text7 = document.getElementById('<%=TextBox7.ClientID%>').value;

if (text1 != "" || text2 != "" || text3 != "" || text4 != "" || text5 != "" || text6 != "" || text7 != "")
{
//Give an Error Message
alert("Your Code");
}
else
{
alert("You need to enter any text");
}
}
</script>

If any one of the text box is entered then your search will be displayed

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox><br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" OnClientClick="GetElemets ()" />



Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kranthi on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
its not work i have firstname,lastname,address if user entered firstname or lastname or address means the search result will be displayed in gridview i use gridview for this using javascript


Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 11/10/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
I dont understand your requirement now, Did it change ? you never told us about a Gridview


Thank you for posting at Dotnetfunda
[Administrator]

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kranthi on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
yes i done that without using gridview. if i want to use gridview means what can i do


Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 11/10/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
So now you want to validate the input in a GridView ? Send me a Defination of your gridview let me see


Thank you for posting at Dotnetfunda
[Administrator]

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kranthi on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
in my form i have 7 textboxes and one searchbutton one gridview. in that gridview i have firstname,lastname,address,state,city,zip,emailid........ and i use like operator for select commant (ex.if i want to search name kranthi means enter k in textbox then the result will be displyed).....now i want to set that search button as mendatory for anyone field should be enter.... if user enter anyone field means the result will be displayed

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhuk on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
So firstname, lastname... are the textboxes. Can you show us the source code of GridView. It would be easy to help.

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kranthi on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None"
Width="933px" onrowdatabound="GridView1_RowDataBound"

>
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:HyperLinkField DataTextField="FirstName" HeaderText="FirstName"
NavigateUrl="~/SaveContacts.aspx" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="Address1" HeaderText="Address1"
SortExpression="Address1" />
<asp:BoundField DataField="Address2" HeaderText="Address2"
SortExpression="Address2" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="City" HeaderText="City"
SortExpression="City" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="Mobile" HeaderText="Mobile"
SortExpression="Mobile" />
<asp:BoundField DataField="ZIP" HeaderText="ZIP"
SortExpression="ZIP" />
<asp:BoundField DataField="EmailID" HeaderText="EmailID"
SortExpression="EmailID" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
and i use follwing code in sqldatasource
SelectCommand="SELECT FirstName, LastName, Address1,Address2, State, City, ZIP, Phone, Mobile, EmailID FROM addcontacts WHERE (FirstName LIKE '%' + @FirstName + '%') AND (LastName LIKE '%' + @LastName + '%') AND (Address1 LIKE '%' + @Address1 + '%') AND (State LIKE '%' + @State + '%') AND (City LIKE '%' + @City + '%') AND (ZIP LIKE '%' + @Zip + '%') AND (EmailID LIKE '%' + @EmailID + '%')"

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 11/10/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

For your TextBox validation using Madhuk script that's working fine.I think your problem is if user give any one condition means you did not got an output in your GridView.
The problem is your SqlCommand check it your SqlCommand because you check all the condition in your query.

Just give which textbox have the input that column only check the condition.

For Example:
If user give condition in firstname and state means

string sCondition=string.Empty;

if(txtfirstname.Text != string.Empty)
{
sCondition = "FirstName LIKE '%' " +txtfirstname.Text+ "%";
}
else if(txtlastname.Text != string.Empty)
{
if(sCondition !=string.Empty)
{
sCondition +=" And ";
}
sCondition += "LastName LIKE '%' " +txtlastname.Text+ "%";
}
.
.
.
.
.
.
else if(txtState.Text != string.Empty)
{
if(sCondition !=string.Empty)
{
sCondition +=" And ";
}
sCondition += "State LIKE '%' " +txtState.Text+ "%";
}



After you get a condition just add the condition in your query

SelectCommand="SELECT FirstName, LastName, Address1,Address2, State, City, ZIP, Phone, Mobile, EmailID FROM addcontacts WHERE "+sCondition +"";


I think its your requirement.Try this way.

Cheers :)



Thanks,
T.Saravanan

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kranthi on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
i want to do this using javascript only

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 11/10/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Using same looping concept in your java script to check each control value and then to add the final condition in your query.
Just try your self in java script if any doubt in your code at the time ask the doubt.

Thanks,
T.Saravanan

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kranthi on: 11/11/2010 [Member] Starter | Points: 25

Up
0
Down
can give me the codings plz i try this but i cant get answer plz

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 11/11/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Sorry for the delay.
Call this function in Button OnClientClick (or) OnClick Event

<Script type="text/javascript">

function getCondition()
{
var sCondition=' ';
if(document.getElementById("txtFirstName").value != '')
{
sCondition = "FirstName LIKE '%" +document.getElementById("txtFirstname").value+ "%'";
}
if(document.getElementById("txtLastName").value != '')
{
if(sCondition !='')
sCondition += " and ";
sCondition += "LastName LIKE '%" +document.getElementById("txtLastName").value+ "%'";
}
.
.
.
.
.
.
if(document.getElementById("txtStateName").value != '')
{
if(sCondition !='')
sCondition += " and ";
sCondition += "State LIKE '%" +document.getElementById("txtStateName").value+ "%'";
}
}
// alert(sCondition);
return sCondition;
</script>


Get the condition and add in your query.

SelectCommand="SELECT FirstName, LastName, Address1,Address2, State, City, ZIP, Phone, Mobile, EmailID FROM addcontacts WHERE "+sCondition +"";


Cheers :)


Thanks,
T.Saravanan

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response