我从SQL获取数据,其中包含header_text:Last_Term和Current_Term 我需要那些header_text更改为选定的下拉值。
<asp:DropDownList ID="ENRDropDownList" AutoPostBack="True" OnSelectedIndexChanged="ENRDropDownList_OnSelectedIndexChanged"
runat="Server">
<asp:ListItem Text="Fall 2016" Value="20172" />
<asp:ListItem Text="Fall 2015" Value="20162" />
<asp:ListItem Text="Fall 2014" Value="20152" />
<asp:ListItem Text="Fall 2013" Value="20142" />
<asp:ListItem Text="Fall 2012" Value="20132" />
<asp:ListItem Text="Fall 2011" Value="20122" />
<asp:ListItem Text="Fall 2010" Value="20112" />
<asp:ListItem Text="Fall 2009" Value="20102" />
</asp:DropDownList>
假设我们选择2016年秋季,则Current_Term应更改为2016年秋季,Last_Term应更改为2015年秋季(动态)。
到目前为止,我已经写出了这个逻辑,即当前和最后一个词都会相应改变。
protected void Page_Load(object sender, EventArgs e)
{
//List<something> clist = new List<something>();s
//clist.Add(new something { cyear = 2016 , pyear = 2015});
if (!Page.IsPostBack)
{
if (Session["term"] != null)
{
ENRDropDownList.SelectedValue = Session["term"].ToString();
}
caption.Text = "Comparison of Fall Enrollment Numbers - " + ENRDropDownList.SelectedItem;
//MyGridView1.Columns[1].HeaderText = clist.Find(new something { cyear = 2015 });
MyGridView1.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
MyGridView2.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
MyGridView3.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
MyGridView4.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
MyGridView5.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
MyGridView6.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
MyGridView7.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
MyGridView8.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
MyGridView9.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
MyGridView10.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
MyGridView11.Columns[2].HeaderText = ENRDropDownList.SelectedItem.Text;
}
}
//string drop = Nameofthedropdownlist.Value;
// datatable.Coloumn["Current_Term"].ColoumnName= drop;
protected void ENRDropDownList_OnSelectedIndexChanged(Object sender, EventArgs e)
{
caption.Text = "Comparison of Fall Enrollment Numbers - " + ENRDropDownList.SelectedItem;
Session["term"] = ENRDropDownList.SelectedValue;
MyGridView1.DataBind();
MyGridView2.DataBind();
MyGridView3.DataBind();
MyGridView4.DataBind();
MyGridView5.DataBind();
MyGridView6.DataBind();
MyGridView7.DataBind();
MyGridView8.DataBind();
MyGridView9.DataBind();
MyGridView10.DataBind();
MyGridView11.DataBind();
string dropValue = ENRDropDownList.SelectedItem.Text;
string drop = ENRDropDownList.SelectedItem.Value.Remove(4,1);
int previousvalue = Convert.ToInt32(drop) - 2;
MyGridView1.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView2.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView3.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView4.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView5.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView6.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView7.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView8.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView9.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView10.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView11.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
//MyGridView1.Columns[1].HeaderText = dropValue;
// MyGridView1.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
MyGridView1.Columns[2].HeaderText = dropValue;
MyGridView2.Columns[2].HeaderText = dropValue;
MyGridView3.Columns[2].HeaderText = dropValue;
MyGridView4.Columns[2].HeaderText = dropValue;
MyGridView5.Columns[2].HeaderText = dropValue;
MyGridView6.Columns[2].HeaderText = dropValue;
MyGridView7.Columns[2].HeaderText = dropValue;
MyGridView8.Columns[2].HeaderText = dropValue;
MyGridView9.Columns[2].HeaderText = dropValue;
MyGridView10.Columns[2].HeaderText = dropValue;
MyGridView11.Columns[2].HeaderText = dropValue;
//string last_Year_Value = ENRDropDownList.SelectedValue
//Console.WriteLine(dropValue);
}
当我运行代码时,页面被加载到哪里,只有Current_Term已更改为所选年份,但last_Term未更改。
但是,当我选择另一年时,那么Last_Term正在改变。 我如何解决这个问题,以便在加载页面时,应该出现last_term。
答案 0 :(得分:0)
MyGridView1.Columns[1].HeaderText = "Fall " + Convert.ToString(previousvalue);
将其替换为 HeaderRow.Cells [要更改的单元格的索引] .Text
MyGridView1.HeaderRow.Cells[1].Text =ddl1.SelectedItem.Value;
肯定会改变网格的列标题。