ReadOnly Property

ImageField.ReadOnly Property

 

Gets or sets a value indicating whether the values of the field specified by the DataImageUrlField property can be modified in edit mode.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public virtual bool ReadOnly { get; set; }

Property Value

Type: System.Boolean

true to indicate that the field values cannot be modified in edit mode; otherwise, false. The default is false.

By default, the values of the field specified by the DataImageUrlField property can be modified by the user when a data-bound control is in edit mode. To prevent the user from changing the values of the field, set this property to true.

System_CAPS_noteNote

In an ImageField object, the DataImageUrlField property usually contains the name of the field that contains the URLs to the images displayed in the object.

The following example demonstrates how to use the ReadOnly property to indicate that the field values that represent the URLs to the images displayed in an ImageField object cannot be modified in edit mode.


<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ImageField ReadOnly Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>ImageField ReadOnly Example</h3>

      <asp:gridview id="EmployeesGrid"
        autogeneratecolumns="false"
        datasourceid="EmployeeSource"
        autogenerateeditbutton="true"
        datakeynames="EmployeeID"   
        runat="server">

        <columns>

          <asp:imagefield dataimageurlfield="PhotoPath"
            alternatetext="Employee Photo"
            nulldisplaytext="No image on file."
            headertext="Photo"  
            readonly="true"/>
          <asp:boundfield datafield="FirstName"
            headertext="First Name"/>
          <asp:boundfield datafield="LastName"
            headertext="Last Name"/>

        </columns>

      </asp:gridview>

      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]"
        updatecommand="Update [Employees] Set [LastName]=@LastName, [FirstName]=@FirstName Where [EmployeeId]=@EmployeeID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>

    </form>
  </body>
</html>

.NET Framework
Available since 2.0
Return to top
Show:
© 2016 Microsoft