Use TemplateColumn in a Datagrid
<%@ Page Language="vb" %>
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.OleDb" %>
<HTML>
<HEAD>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim dbConn As OleDbConnection
Dim myAdapter As OleDbDataAdapter
Dim sqlCmd As String
Dim strConn As String
Dim oDataSet As New DataSet
strConn = ""
strConn = strConn & "Provider=Microsoft.Jet.OLEDB.4.0;"
strConn = strConn & "Data Source=" & Server.MapPath("database/utenti.mdb") & ";"
strConn = strConn & "Persist Security Info=False"
sqlCmd = ""
sqlCmd = sqlCmd & "SELECT "
sqlCmd = sqlCmd & " nome, "
sqlCmd = sqlCmd & " cognome, "
sqlCmd = sqlCmd & " email "
sqlCmd = sqlCmd & " FROM utenti"
dbConn = New OleDbConnection(strConn)
myAdapter = New OleDbDataAdapter(sqlCmd, dbConn)
myAdapter.Fill(oDataSet, "utenti")
myDatagrid.DataSource = oDataSet.Tables("utenti").DefaultView
myDatagrid.DataBind()
End Sub
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="myDatagrid" runat="server" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="4" Width="460px" AutoGenerateColumns="False">
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="nome">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.nome") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.nome") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="cognome">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cognome") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cognome") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="email">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.email") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.email") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>
Download Code...
Print Page