AttributeCollection.Add(String, String) Metoda

Definicja

Dodaje atrybut do obiektu kontrolki AttributeCollection serwera.

public:
 void Add(System::String ^ key, System::String ^ value);
public void Add (string key, string value);
member this.Add : string * string -> unit
Public Sub Add (key As String, value As String)

Parametry

key
String

Nazwa atrybutu.

value
String

Wartość atrybutu.

Przykłady

W poniższym przykładzie pokazano, jak za pomocą Add metody programowo dodać atrybut do obiektu sterowania AttributeCollection serwera ASP.NET.

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

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

<script runat="server">
 
    protected void SubmitBtn_Click(object sender, EventArgs e)
    {
        firstselect.Attributes.Add("Multiple", "True");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AttributeCollection Example</title>
</head>

 <body>
    <form id="form1" runat="server">
    <div>
    Make a selection:
    <select id="firstselect" 
            runat="server">
       <option>This</option>
       <option>That</option>
       <option>Other</option>
    </select>
    <br/><br/>

    <input type="submit" 
           id="submitbtn"
           value="modify attribute" 
           onserverclick="SubmitBtn_Click" 
           runat="server"/>
    </div>
 </form>
 </body>
 </html>
<%@ Page Language="VB" %>

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

<script runat="server">
 
    Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        FirstSelect.Attributes.Add("Multiple", "True")
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AttributeCollection Example</title>
</head>

 <body>
    <form id="form1" runat="server">
    <div>
    Make a selection:
    <select id="firstselect" 
            runat="server">
       <option>This</option>
       <option>That</option>
       <option>Other</option>
    </select>
    <br/><br/>

    <input type="submit" 
           id="submitbtn"
           value="modify attribute" 
           onserverclick="submitbtn_click" 
           runat="server"/>
    </div>
 </form>
 </body>
 </html>

Uwagi

Jeśli ciąg w parametrze value zawiera znak ampersand (&), znak jest automatycznie kodowany. Wynikowa reprezentacja HTML to "&".

Dotyczy

Zobacz też