AttributeCollection.Add(String, String) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menambahkan atribut ke objek kontrol AttributeCollection server.
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)
Parameter
- key
- String
Nama atribut.
- value
- String
Nilai atribut.
Contoh
Contoh berikut menunjukkan cara menggunakan Add metode untuk menambahkan atribut secara terprogram ke objek kontrol AttributeCollection server 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>
Keterangan
Jika string dalam value
parameter berisi ampersand (&), karakter akan dikodekan secara otomatis. Representasi HTML yang dihasilkan adalah "&".