GridView的几个操作

来源:互联网 发布:全国城市街道数据库 编辑:程序博客网 时间:2024/05/03 12:40

*//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.....
    }

    protected void gvGrade_RowEditing(object sender, GridViewEditEventArgs e)
    
{
        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/ 十分感谢!)

 protected void bnShowFail_Click(object sender, EventArgs e)
    
{
        
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> 

原创粉丝点击