0% found this document useful (0 votes)
20 views

Compact Operators: Dim As Dim As

The document contains code snippets for three different tasks: 1) A compact operator example that appends strings together and displays the results. 2) Code to add items to a dropdownlist and avoid duplication by checking if the item already exists. 3) Gridview code using templates to allow editing, updating, and deleting records with validation.

Uploaded by

Anidkaran
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Compact Operators: Dim As Dim As

The document contains code snippets for three different tasks: 1) A compact operator example that appends strings together and displays the results. 2) Code to add items to a dropdownlist and avoid duplication by checking if the item already exists. 3) Gridview code using templates to allow editing, updating, and deleting records with validation.

Uploaded by

Anidkaran
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Compact operators 

Dim result As New System.Text.StringBuilder
Dim testString As String = "Abcdef"
  result.Append("String ").AppendLine(testString)
  testString &= "ghi"
  result.Append("&= ghi ... ").AppendLine(testString)
  testString += "jkl"
  result.Append("+= jkl ... ").AppendLine(testString)
  Console.WriteLine(result.ToString())

DropDownlist Avoiding Duplication

int a=1,i,n;
n = DropDownList1.Items.Count;
if (n == 0)
{
DropDownList1.Items.Add(TextBox1.Text);
}
else
{
for (i = 0; i <= n - 1; i++)
{
if (DropDownList1.Items[i].ToString() == TextBox1.Text)
{
a = a + 1;
}
}
if (a == 2)
{
Response.Write("Already Exists");
}
else
{
DropDownList1.Items.Add(TextBox1.Text);
}
}

Gridview Edit,Update,Delete Using Code

<Columns>
<asp:TemplateField>
<ItemTemplate>
<span onclick="return confirm('Are you sure to Delete the record?')">
<asp:LinkButton ID="lnkB" runat="Server" CommandName="Delete"
Text="Delete"></asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%# Eval("name")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="name" runat="Server" Columns="30"
Text='<%# Eval("name") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="req1" runat="Server"
ControlToValidate="name" Text="*"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>

You might also like