The OnDataBound event is raised when the databinding logic has been completed, at this point in time you can then perform any addtional tasks before the page finishes loading.

    1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebSample.Default" %>

    2 

    3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    4 <html xmlns="http://www.w3.org/1999/xhtml">

    5 <head runat="server">

    6     <title>Untitled Page</title>

    7 </head>

    8 <body>

    9     <form id="form1" runat="server">

   10     <div>

   11 

   12         <script runat="server">

   13             protected void ddlStudent_DataBound(object sender, EventArgs e)

   14             {

   15                 //this.ddd

   16                 ddlStudent.Items.Add("Last Item");

   17                 ddlStudent.SelectedIndex = 0;

   18             }

   19         </script>

   20 

   21         <h2>

   22             Events</h2>

   23         <div>

   24             DataBound Event</div>

   25         <div>

   26             <asp:DropDownList ID="ddlStudent" runat="server" OnDataBound="ddlStudent_DataBound"

   27                 DataSourceID="SqlDataSourceTI" DataTextField="TI" DataValueField="TI" AutoPostBack="true">

   28                 <asp:ListItem>List Item 1</asp:ListItem>

   29                 <asp:ListItem>List Item 2</asp:ListItem>

   30                 <asp:ListItem>List Item 4</asp:ListItem>

   31             </asp:DropDownList>

   32             <asp:SqlDataSource ID="SqlDataSourceTI" runat="server" ConnectionString="<%$ ConnectionStrings:PI_RTCF_ReportingConn %>"

   33                 SelectCommand="usp_SelectTIAll" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

   34         </div>

   35     </div>

   36     </form>

   37 </body>

   38 </html>

 
* iOS Development * OS X * Product Review