asp.net gridview怎么动态修改,怎么绑定在list中? 要代码
发布网友
发布时间:2023-10-13 11:43
我来回答
共1个回答
热心网友
时间:2023-10-09 09:53
这个要后台自己写代码
比如你的list控件
这是我的dropdownlist的例子
你改成list之后,findControl也是你对应的
然后就是你自己对应的不是选择问题,而是添加项目
DropDownList ddl;
if (!IsPostBack)
{
string sqlstr = "select * from project";
SqlConnection sqlcon = new SqlConnection(database.database);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "西艾工作室");
GridView1.DataSource = myds;
GridView1.DataBind();
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
DataRowView mydrv = myds.Tables["西艾工作室"].DefaultView[i];
if (Convert.ToString(mydrv["date"]).Trim() == "一月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 11;
}
if (Convert.ToString(mydrv["date"]).Trim() == "二月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 1;
}
if (Convert.ToString(mydrv["date"]).Trim() == "三月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 5;
}
if (Convert.ToString(mydrv["date"]).Trim() == "四月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 9;
}
if (Convert.ToString(mydrv["date"]).Trim() == "五月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 10;
}
if (Convert.ToString(mydrv["date"]).Trim() == "六月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 3;
}
if (Convert.ToString(mydrv["date"]).Trim() == "七月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 4;
}
if (Convert.ToString(mydrv["date"]).Trim() == "八月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 0;
}
if (Convert.ToString(mydrv["date"]).Trim() == "九月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 2;
}
if (Convert.ToString(mydrv["date"]).Trim() == "十月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 8;
}
if (Convert.ToString(mydrv["date"]).Trim() == "十一月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 9;
}
if (Convert.ToString(mydrv["date"]).Trim() == "十二月")
{
ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList2");
ddl.SelectedIndex = 6;
}
}
sqlcon.Close();
}