Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi this is anil i want to compare textbox control and gridview row index:

Explanation:In textbox one string is there example anil,inside textbox control the name is anil:In gridview in row index same name anil so i want to compare this to...

is there any way....



Regards,

Anilkumar.
Posted

1 solution

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow item in GridView1.Rows)
        {
            //Use the proper column index
            int colindex = 0;
            if (item.Cells[colindex].Text.Equals(TextBox1.Text, StringComparison.OrdinalIgnoreCase))
            {
               //Add your logic here
            }
        }
    }
 
Share this answer
 
Comments
honey143206 17-Jun-11 4:26am    
If i want to use multiple textboxes to compare then ....... is there any way plz
honey143206 17-Jun-11 4:33am    
if (GridView1.Rows.Count > 0)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
if (GridView1.Rows.Count >= i)
{

string Mode = "U";
pr.School = int.Parse(txtschoolId.Text);
pr.Mode = Mode;
logic.Insert(pr);

foreach (GridViewRow item in GridView1.Rows)
{

//for (int j = 0; j < GridView1.Rows.Count; j++)
//{
//if (txtschoolName.Text =
//{
// count = 1;

// break;
//}
int colindex = 0;
if (item.Cells[colindex].Text.Equals(txtschoolName.Text, StringComparison.OrdinalIgnoreCase))
{
count = 1;
break;
}

if (count == 0)
{
string Mode1 = "U";
pr.School = int.Parse(txtschoolId.Text);
pr.SchoolName = txtschoolName.Text;
pr.PrincipleName = txtprincipleName.Text;
pr.LandlineNo = int.Parse(txtLandlineno.Text);
pr.MobileNo = int.Parse(txtmobileno.Text);
pr.Address = txtaddress.Text;
pr.Mode = Mode1;
logic.Insert(pr);
Label7.Text = "Updated Sucessfully";
}
else
{
Label7.Text = "Already Exists Please change the data";
}
}
}
else
{
if (i == GridView1.Rows.Count - 1)
{
Label7.Text = "Fisrt Select from the Gridview";
}
}
}



}

this is my code please chect it ..... and if any changes plz update

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900