web stats analysis

vb.net Archive

How to Fixed GridView’s Header and Footer when scrolling in vb.net?

Use below 2 Css Classes for GridView Header and footer.


.gridHeader {
font-weight:bold;
background-color: Green;
position:relative;
top:expression(this.parentNode.parentNode.parentNode.scrollTop-1);
}

.gridFooter {
font-weight:bold;
background-color: Green;
position:relative;

bottom:expression(scrollBottom(this.parentNode.parentNode.parentNode.parentNode));
}

Use below JavaScript to compute Footer’s Position.


<script language="javascript" type="text/javascript">

function scrollBottom(p_oElem)
{
return p_oElem.scrollHeight - p_oElem.scrollTop - p_oElem.clientHeight;

}
</script>

Create GridView inside a Panle.


<asp:Panel runat="server" ID="pnlContainer" ScrollBars="Auto" Height="150px" Width="400">
<asp:GridView ShowFooter="True" runat="server" Width="96%" ID="gvDemo"

AutoGenerateColumns="False">
<HeaderStyle CssClass="gridHeader" />
<FooterStyle CssClass="gridFooter" />
<Columns>
<asp:TemplateField HeaderText="a1">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("a1") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
a1 Footer Here
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="a2">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("a2") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
a2 Footer Here
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>

In the Page_Load function we Bind the data source to GridView in Code Behide:


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dtbl As New DataTable
dtbl.Columns.Add("a1")
dtbl.Columns.Add("a2")
Dim dr As DataRow
For i As Integer = 0 To 10
dr = dt.NewRow
dr(0) = "a1" & i
dr(1) = "a2" & i
dtbl.Rows.Add(dr)
Next
Me.gvDemo.DataSource = dtbl
Me.gvDemo.DataBind()
End Sub

How to pass variables or values from one asp vb code page to another?

Using below way to pass variables or values from one asp vb code page to another.

Using session easy way in asp.net/VB.net.
Session(“TestVariable”) = “aaaa”
From another .aspx.vb page you can now use below value. Example:
Dim str as String = “”
str = Session(“TestVariable”)
You can access this page on any of your .aspx pages for using below references .
Session(“TestVariable”).

How to create dynamically html table in vb.net?

Generate insert statements from a specific table data using SQL Server in asp.net

I have a solution:

Just copy the below script into your asp page.


<script  runat="server">
Sub submit(sender As Object, e As EventArgs)
Dim row,numrows,numcells,j,i
row=0
numrows=cint(rows1.Value)
numcells=cint(cells1.Value)
for j=1 to numrows
Dim r As New HtmlTableRow()
row=row+1
for i=1 to numcells
Dim c As New HtmlTableCell()
c.Controls.Add(New LiteralControl("row " & j & ", cell " & i))
r.Cells.Add(c)
next
t1.Rows.Add(r)
t1.Visible=true
next
End Sub
</script>

Then write the below code into your html page.


<!DOCTYPE html>
<html>
<body>

<form runat="server">
<p>Table rows:
<select id="rows1" runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br>Table cells:
<select id="cells1" runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br><br>
<input type="submit" value="Display Table" runat="server" OnServerClick="submit">
</p>
<table id="t1" border="1" runat="server" visible="false"/>
</form>

</body>
</html>

ASP.NET: ListView display Image based on database column being Null or not.

Display images from SQL server database using asp.net.

I try and got solution is below:

Just typed below code in your aspx page:


<ItemTemplate>
<tr style="">
<td>
<asp:Literal ID="lblPic" runat="server" />
...
...
</td>
<td>
<a href="?team=<%# TeamNumber() %>&player=<%# Eval("PlayerKey") %>"><asp:Label ID="PlayerLabel"

runat="server" Text='<%# Eval("Player") %>' /></a>
</td>
<td>
<asp:Label ID="PositionLabel" runat="server" Text='<%# Eval("Position") %>' />
</td>
</tr>
</ItemTemplate>

Just type the below code into your code behind.


Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs)
If e.Item.ItemType = ListViewItemType.DataItem Then
Dim lblPic As Literal = CType(e.Item.FindControl("lblPic"), Literal)
Dim rowView As System.Data.DataRowView
rowView = CType(e.Item.DataItem, System.Data.DataRowView)

If Convert.IsDbNull(rowView("hasPic") = true then
lblPic.Text = "<img src=\"/Images/sports/never.gif\" alt=\"Picture Available\" CssClass=\"icon right\" />"
Else
lblPic.Text = "<img/> To Display Pic"
End If
End If
End Sub