Gridview行委托 [英] Gridview row deleation
问题描述
你好,
我正在通过选择查询在运行时生成gridview,但是现在我正在检查一个条件,并且根据该条件我想删除该gridview的垂直行(如果它在窗口应用程序中满足该条件的话)然后我如何删除row.i提供我的代码下面
Hello,
I am generating the gridview at runtime through select query but now i am checking one condition and as per that condition i want delete that perticular row of gridview if it fullfills the condition in window application then how i can delete row.i am giving my code below
private void LoadgvFeesData()
{
DBAccess objDBAccessCF = new DBAccess();
long _SlabID=getSlabID();
float totalfees = 0;
try
{
objDBAccessCF.OpenConnection();
string SelectCommand = "SELECT SM.ID As SlabFeeTypeMappingID , FT.TypeName, SM.Amount, SM.Amount As PayAmount, SM.FeeSlabsID, SM.Frequency, SM.FeeTypeID, FS.Name FROM tbl_Fee_Slabs FS INNER JOIN
tbl_SlabFeeTypeMapping SM ON FS.ID = SM.FeeSlabsID INNER JOIN
tbl_Fee_Type FT ON SM.FeeTypeID = FT.ID where FS.ID=@1";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("1", _SlabID);
DataTable dt = new DataTable();
dt.Load((IDataReader)objDBAccessCF.ExecuteForReader(SelectCommand, param));
gvFees.DataSource = dt;
if (dt.Rows.Count> 0)
{
label14.Text = dt.Rows[0]["SlabFeeTypeMappingID"].ToString();
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[0]["Frequency"].ToString() == "One Time")
{
string Selectcmd = "Select StudentID from tbl_Fee_Receipt where SlabFeeMappingId=@1 and StudentID=@2 ";
SqlParameter[] para = new SqlParameter[2];
para[0] = new SqlParameter("1", label14.Text);
para[1] = new SqlParameter("2", cmbRollNO.SelectedValue);
DataTable dt1 = new DataTable();
dt1.Load((IDataReader)objDBAccessCF.ExecuteForReader(Selectcmd, para));
if (dt.Rows.Count == 1)
{
}
else
{
//Here i want to delete particular gridview row if condition fullfills
}
}
}
}
}
}
推荐答案
检查代码后,有些事情对我完全没有意义.例如:
After inspecting you''re code there are some things that do not make sense to me at all. For example:
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[0]["Frequency"].ToString() == "One Time")
{
...
}
}
为什么要进行for循环,然后始终检查dt.Rows [0]而不是dt.Rows [i]?
然后另一件事:
Why are you making a for loop and then checking dt.Rows[0] all the time instead of dt.Rows[i]?
Then another thing:
DataTable dt1 = new DataTable();
dt1.Load((IDataReader)objDBAccessCF.ExecuteForReader(Selectcmd, para));
if (dt.Rows.Count == 1)
{
}
else
{
//Here i want to delete particular gridview row if condition fullfills
}
为什么要创建另一个名为 dt1 的数据表,然后再执行( dt .Rows.Count == 1)而不是( dt1 ). Rows.Count == 1)?
对那些我只是想知道的事情.在我看来,您应该将此代码插入else语句中:
Why do you make a second datatable called dt1 and then do another check (dt.Rows.Count == 1) instead of (dt1.Rows.Count == 1)?
Right those things i was just wondering about. Seems to me like you should insert this code inside the else statement:
if (dt1.Rows.Count == 1)
{
}
else
{
dt.Rows.RemoveAt(i);
}
这篇关于Gridview行委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!