web 2.0

ASP.NET(vb.net) & ClientID

ASP.NET(vb.net) & ClientID() - ClientID() : Learn and example how to use Asp.net get a ClientID on Web Form.

ShotDev Focus:
- ASP.NET(vb.net) & ClientID()

Example

ClientID.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ClientID.aspx.vb" Inherits="Client" %>

<!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>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:DataGrid id="myDataGrid" runat="server" AutoGenerateColumns="False"
DataKeyField="CustomerID">
<Columns>
<asp:TemplateColumn HeaderText="Delete">
<ItemTemplate> &nbsp;<asp:CheckBox ID="chkDel" runat="server" />
</ItemTemplate>
<HeaderTemplate>
&nbsp;<asp:Label ID="Delete" runat="server" Text="Delete"></asp:Label>
</HeaderTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="CustomerID">
<ItemTemplate>
<asp:Label id="lblCustomerID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CustomerID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<asp:Label id="lblName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Email">
<ItemTemplate>
<asp:Label id="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="CountryCode">
<ItemTemplate>
<asp:Label id="lblCountryCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CountryCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Budget">
<ItemTemplate>
<asp:Label id="lblBudget" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Budget") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Used">
<ItemTemplate>
<asp:Label id="lblUsed" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Used") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid><br />
<asp:Label ID="lblText" runat="server" Text="Client ID"></asp:Label>
<asp:TextBox ID="txtClientID" runat="server" Width="187px"></asp:TextBox>
</form>
</body>
</html>

ClientID.aspx.vb


Imports System.Data
Imports System.Data.OleDb
Partial Class Client
Inherits System.Web.UI.Page
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim strSQL As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database/mydatabase.mdb") & ";"
objConn = New OleDbConnection(strConnString)
objConn.Open()

If Not Page.IsPostBack() Then
BindData()
End If
End Sub

Protected Sub BindData()
strSQL = "SELECT * FROM customer"

Dim dtReader As OleDbDataReader
objCmd = New OleDbCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()

'*** BindData to DataGrid ***'
myDataGrid.DataSource = dtReader
myDataGrid.DataBind()

dtReader.Close()
dtReader = Nothing

End Sub

Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
objConn.Close()
objConn = Nothing
End Sub

Protected Sub myDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles myDataGrid.ItemDataBound

'*** Check Delete ***'
Dim chkDel As CheckBox = CType(e.Item.FindControl("chkDel"), CheckBox)
If Not IsNothing(chkDel) Then
With chkDel
chkDel.Attributes.Add("OnClick", "document.form1." & Me.txtClientID.ClientID & ".value = '" & chkDel.ClientID & "'")
End With
End If
End Sub
End Class

Screenshot

ASP.NET(vb.net) & ClientID()
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.