GridView各事件

1protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
 2{
 3    if (e.Exception != null)
 4    {
 5        // Display a user-friendly message
 6        ExceptionDetails.Visible = true;
 7        ExceptionDetails.Text = "There was a problem updating the product. ";
 8
 9        if (e.Exception.InnerException != null)
10        {
11            Exception inner = e.Exception.InnerException;
12
13            if (inner is System.Data.Common.DbException)
14                ExceptionDetails.Text += "Our database is currently experiencing problems. Please try again later.";
15            else if (inner is NoNullAllowedException)
16                ExceptionDetails.Text += "There are one or more required fields that are missing.";
17            else if (inner is ArgumentException)
18            {
19                string paramName = ((ArgumentException)inner).ParamName;
20                ExceptionDetails.Text += string.Concat("The ", paramName, " value is illegal.");
21            }

22            else if (inner is ApplicationException)ExceptionDetails.Text += inner.Message;
23        }

24
25        // Indicate that the exception has been handled
26        e.ExceptionHandled = true;
27
28        // Keep the row in edit mode
29        e.KeepInEditMode = true;
30    }

31}

32

protected void Suppliers_RowCreated(object sender, GridViewRowEventArgs e)
{
   
if (e.Row.RowType == DataControlRowType.DataRow)
    {
       
// Grab a reference to the Literal control
        Literal output = (Literal)e.Row.FindControl("RadioButtonMarkup");

       
// Output the markup except for the "checked" attribute
        output.Text = string.Format(
           
@"<input type=""radio"" name=""SuppliersGroup"" " +
           
@"id=""RowSelector{0}"" value=""{0}"" />", e.Row.RowIndex);
    }
}

posted @ 2010-03-02 08:51  三颗屎  阅读(156)  评论(0编辑  收藏  举报