你可能会在我附上的照片中看到,有一个下拉菜单,一个按钮和两个网格视图。当我选择下拉值并且第一个网格将填充时 比我选择单选按钮并单击应用按钮比第二个网格将 填补。问题是现在再次开始我选择下拉它将显示第一个网格并选择单选按钮并单击按钮并仅显示新记录,旧的将删除所以我想要两个
protected void btnapply_Click(object sender, EventArgs e)
{
SelectModel();
}
public void SelectModel()
{
if (IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[6] { new DataColumn("Software"), new DataColumn("id"), new DataColumn("module"), new DataColumn("rdoread"), new DataColumn("rdoreadmodify"), new DataColumn("all") });
foreach (GridViewRow row in Gridmodule.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRead = (row.Cells[0].FindControl("rdoread") as CheckBox);
CheckBox chkReadModify = (row.Cells[0].FindControl("rdoreadmodify") as CheckBox);
CheckBox chkAll = (row.Cells[0].FindControl("rdoall") as CheckBox);
if (chkRead.Checked)
{
string id = (row.Cells[1].FindControl("lblid") as Label).Text;
string module = (row.Cells[2].FindControl("lblmodule") as Label).Text;
bool read = true;
bool readmodify = false;
bool all = false;
string soft = (drpsoftware.SelectedItem.ToString());
dt.Rows.Add(soft, id, module, read, readmodify, all);
}
if (chkReadModify.Checked)
{
string id = (row.Cells[1].FindControl("lblid") as Label).Text;
string module = (row.Cells[2].FindControl("lblmodule") as Label).Text;
bool read = false;
bool readmodify = true;
bool all = false;
string soft = (drpsoftware.SelectedItem.ToString());
dt.Rows.Add(soft, id, module, read, readmodify, all);
}
if (chkAll.Checked)
{
string id = (row.Cells[1].FindControl("lblid") as Label).Text;
string module = (row.Cells[2].FindControl("lblmodule") as Label).Text;
bool read = false;
bool readmodify = false;
bool all = true;
string soft = (drpsoftware.SelectedItem.ToString());
dt.Rows.Add(soft, id, module, read, readmodify, all);
}
}
}
gridselected.DataSource = dt;
gridselected.DataBind();
}
我希望当我第一次按下此按钮时它会填充网格,当我再次按下相同的按钮时,它永远不会删除以前的数据并用旧的填充新数据。