asp.net 单机按钮显示内容gridview中
单机按钮1的时候从数据库读取内容到gridview中,单机按钮2的时候怎么让他增加一行,不要把按钮1显示的内容没有了,我做了一个方法单机按钮2的时候就重新加载整个页面了,...
单机按钮1的时候从数据库读取内容到gridview中,单机按钮2的时候怎么让他增加一行,不要把按钮1显示的内容没有了,我做了一个方法单机按钮2的时候就重新加载整个页面了,求大神,
public void displayGridView(ref DataTable dtOld, DataTable dtNew)
{
ArrayList dtOldParams = new ArrayList();
if (dtOld.Rows.Count == 0 && dtNew.Rows.Count > 0)
{
for (int i = 0; i < dtNew.Columns.Count; i++)
{
dtOld.Columns.Add(dtNew.Columns[i].ColumnName);
}
for (int i = 0; i < dtNew.Rows.Count; i++)
{
for (int j = 0; j < dtNew.Columns.Count; j++)
{
dtOldParams.Add(dtNew.Rows[i][j].ToString());
}
dtOld.Rows.Add(dtOldParams.ToArray());
dtOldParams.Clear();
}
}
else if (dtOld.Rows.Count > 0 && dtNew.Rows.Count > 0)
{
for (int i = 0; i < dtNew.Rows.Count; i++)
{
for (int j = 0; j < dtNew.Columns.Count; j++)
{
dtOldParams.Add(dtNew.Rows[i][j].ToString());
}
dtOld.Rows.Add(dtOldParams.ToArray());
dtOldParams.Clear();
}
}
} 展开
public void displayGridView(ref DataTable dtOld, DataTable dtNew)
{
ArrayList dtOldParams = new ArrayList();
if (dtOld.Rows.Count == 0 && dtNew.Rows.Count > 0)
{
for (int i = 0; i < dtNew.Columns.Count; i++)
{
dtOld.Columns.Add(dtNew.Columns[i].ColumnName);
}
for (int i = 0; i < dtNew.Rows.Count; i++)
{
for (int j = 0; j < dtNew.Columns.Count; j++)
{
dtOldParams.Add(dtNew.Rows[i][j].ToString());
}
dtOld.Rows.Add(dtOldParams.ToArray());
dtOldParams.Clear();
}
}
else if (dtOld.Rows.Count > 0 && dtNew.Rows.Count > 0)
{
for (int i = 0; i < dtNew.Rows.Count; i++)
{
for (int j = 0; j < dtNew.Columns.Count; j++)
{
dtOldParams.Add(dtNew.Rows[i][j].ToString());
}
dtOld.Rows.Add(dtOldParams.ToArray());
dtOldParams.Clear();
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询