如何检查gridview中存在的重复值 [英] How to check duplicate values exists in gridview
本文介绍了如何检查gridview中存在的重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您正在使用gridview。我想通过使用foreach循环.Mean将数据保存在数据库中,同时我必须检查重复记录是否在gridview中不存在。任何人都可以建议我该怎么做。在此先感谢。
Hi am using a gridview . I want to save the data in the DB by using foreach loop .Mean while I have to check whether duplicate records are there are not in gridview . Can any one suggest me how to do . Thanks in advance.
//Before inserting/updating the formula, insert the existing formula in OldFormula table
btnSave.Enabled = false;
fpsPL.FeedTypeId = Convert.ToInt32(ddlFeedType.SelectedValue);
fpsPL.UpdatedBy = Session["username"].ToString();
bool archived = false;
archived = fpsBAL.InsertOldFormula(fpsPL);
if (archived)
{
string products = "";
foreach (GridViewRow row in gvFormula.Rows)
{
TextBox txt = (TextBox)row.Cells[2].FindControl("txtWeight");
DropDownList ddlproduct = (DropDownList)row.FindControl("ddlproduct");
if (txt != null)
{
if (txt.Text.Trim() != "" && Convert.ToSingle(txt.Text.Trim()) > 0)
{
fpsPL.FeedTypeId = Convert.ToInt32(ddlFeedType.SelectedValue);
fpsPL.Product = ddlproduct.SelectedItem.Text;
fpsPL.Weight = Convert.ToSingle(txt.Text.Trim());
fpsPL.UpdatedBy = Session["username"].ToString();
bool added = false;
added = fpsBAL.InsertFormulaProduct(fpsPL);
if (!added)
{
products = row.Cells[2].Text.Trim() + ",";
}
}
}
}
if (products.Trim() != "")
{
//Few products have not been added in formula, convey the same
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "InsertProduct", "alert('Products " + products.TrimEnd(',') + " are not added into formula.');", true);
}
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Archive", "alert('Insertion/Updation failed, check data once');", true);
}
btnSave.Enabled = true;
推荐答案
try
{
if (MSGrid1.Col == 0)
{
putslno();
}
else if (MSGrid1.Col == 2)
{
int currow = MSGrid1.Row;
for (int i = 1; i <= MSGrid1.Rows - 1; i++)
{
for (int j = i + 1; j <= MSGrid1.Rows - 1; j++)
{
if ((MSGrid1.get_TextMatrix(j, 1) == MSGrid1.get_TextMatrix(i, 1)))
{
if (MSGrid1.get_TextMatrix(j, 1) != "")
{
MessageBox.Show("This Item Name is already selected");
MSGrid1.set_TextMatrix(j, 1, "");
MSGrid1.set_TextMatrix(j, 2, "");
MSGrid1.set_TextMatrix(j, 3, "");
MSGrid1.set_TextMatrix(j, 4, "");
MSGrid1.set_TextMatrix(j, 5, "");
MSGrid1.Focus();
MSGrid1.Col = 1;
return;
}
}
}
}
PlaceTxtBox();
}
else if (MSGrid1.Col == 4)
{
PlaceTxtBox();
}
else if (MSGrid1.Col == 6)
{
GridCombo();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
i使用msfluxgirid你可以使用数据网格chk相同的逻辑
}
i have used msfluxgirid u can chk same logic with data grid
这篇关于如何检查gridview中存在的重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文