*//Hide 'StuID' cloumn
protected void gvGrade_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[2].Visible = false;
//if gvGrade.AutoPaging=true It's something wrong.....
}
{
gvGrade.EditIndex = e.NewEditIndex;
gvGrade.DataSource = CreateDataSource();
gvGrade.DataBind();
}
protected void gvGrade_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
OleDbConnection updateConn = new OleDbConnection(connString);
updateConn.Open();
In VS2005 It's very difficult to fetch the content of Hidden Column , so Fetch it from DataSet
Calculate "colCount" because in "Page_Load" has "if(!IsPostBack)
Define a arraylist to save "CourseName"
Execute Update
updateConn.Close();
}
*顯示不及格分數:(使用了“清清月兒”的辦法http://blog.csdn.net/21aspnet/ 十分感謝!)
{
for (int i = 0; i < gvGrade.Rows.Count; i++)
{
for (int j = 1; j < gvGrade.Rows[i].Cells.Count; j++)
{
string score = gvGrade.Rows[i].Cells[j].Text.Trim();
if (!System.Text.RegularExpressions.Regex.IsMatch(score, @"^[0-9]+$"))
continue;
if (Convert.ToDouble(score) < 60)
{
//If < 60 change bgcolor for the cell & ID
gvGrade.Rows[i].Cells[j].BackColor = System.Drawing.Color.Red;
gvGrade.Rows[i].Cells[0].BackColor = System.Drawing.Color.Red;
}
}
}
*點擊學號顯示學生詳細信息(超鏈接列) //學會用Eval了,^_^
admin.aspx:
<asp:CommandField CancelText="取消" DeleteText="刪除" EditText="編輯" ShowEditButton="True"
UpdateText="確定" >
<ItemStyle Width="80px" />
<ControlStyle Width="80px" />
</asp:CommandField>
<asp:TemplateField HeaderText="學號">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=<%#"./StuInfo.aspx?StuId="+Eval("學號") %>
Text='<%# Eval("學號") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>