Saturday, March 31, 2012
set ASP.NET datagrid image based on SQL table value
one image if the value in my SQL table is true and another if it is
false. Here is my code.
<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false"
Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
absolute; TOP: 0px" runat="server"
BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
BackColor="#DEBA84" CellPadding="3"
AutoGenerateColumns="False" CellSpacing="2">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510"
BackColor="#F7DFB5"></FooterStyle>
<Columns>
</asp:BoundColumn>
<asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Check or X">
<ItemTemplate>
<img src='\Check.gif'>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>
I want to show the 'Check.gif' if an SQL table value is True or
'x.gif' if it is false.
Thaks for any help, This ASP.NET is kicking my butt.Hi Rob,
Just jam a little
<IMG src='<%#iif(DataBinder.Eval(Container,
"DataItem.Boolean"),"Check.gif","x.gif") %>'>
in there and you should be okay.
BTW, I had some problems with your markup. My fixed version is below.
Does this help?
Ken
Microsoft MVP [ASP.NET]
Toronto
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" runat="server" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px"
BackColor="#DEBA84" CellPadding="3" AutoGenerateColumns="False"
CellSpacing="2">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510" BackColor="#F7DFB5"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Check or X">
<ItemTemplate>
<IMG src='<%#iif(DataBinder.Eval(Container,
"DataItem.Boolean"),"Check.gif","x.gif") %>'>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>
"Rob Rogers" <rob@.natltc.com> wrote in message
news:7ee34208.0407141234.18d2abdd@.posting.google.com...
>I have an ASP.NET datagrid that loads an image. I would like to load
> one image if the value in my SQL table is true and another if it is
> false. Here is my code.
> <%@. Page Language="vb" AutoEventWireup="false"
> Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
> <meta name="vs_defaultClientScript" content="VBScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
> absolute; TOP: 0px" runat="server"
> BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
> BackColor="#DEBA84" CellPadding="3"
> AutoGenerateColumns="False" CellSpacing="2">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#738A9C"></SelectedItemStyle>
> <ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#A55129"></HeaderStyle>
> <FooterStyle ForeColor="#8C4510"
> BackColor="#F7DFB5"></FooterStyle>
> <Columns>
> </asp:BoundColumn>
> <asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
> <ItemStyle Width="150px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Check or X">
> <ItemTemplate>
> <img src='\Check.gif'>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> </Columns>
> <PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
> Mode="NumericPages"></PagerStyle>
> </asp:DataGrid>
> </form>
> </body>
> </HTML>
> I want to show the 'Check.gif' if an SQL table value is True or
> 'x.gif' if it is false.
> Thaks for any help, This ASP.NET is kicking my butt.
BTW, here's the code behind and data source that I used for that example.
"Boolean" is the name of the field as well as the type.
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
MyGrid.DataSource = CreateDataSource()
MyGrid.DataBind()
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("City", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Rob Rogers" <rob@.natltc.com> wrote in message
news:7ee34208.0407141234.18d2abdd@.posting.google.com...
>I have an ASP.NET datagrid that loads an image. I would like to load
> one image if the value in my SQL table is true and another if it is
> false. Here is my code.
> <%@. Page Language="vb" AutoEventWireup="false"
> Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
> <meta name="vs_defaultClientScript" content="VBScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
> absolute; TOP: 0px" runat="server"
> BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
> BackColor="#DEBA84" CellPadding="3"
> AutoGenerateColumns="False" CellSpacing="2">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#738A9C"></SelectedItemStyle>
> <ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#A55129"></HeaderStyle>
> <FooterStyle ForeColor="#8C4510"
> BackColor="#F7DFB5"></FooterStyle>
> <Columns>
> </asp:BoundColumn>
> <asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
> <ItemStyle Width="150px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Check or X">
> <ItemTemplate>
> <img src='\Check.gif'>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> </Columns>
> <PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
> Mode="NumericPages"></PagerStyle>
> </asp:DataGrid>
> </form>
> </body>
> </HTML>
> I want to show the 'Check.gif' if an SQL table value is True or
> 'x.gif' if it is false.
> Thaks for any help, This ASP.NET is kicking my butt.
Thanks, Thats just what I needed.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
set ASP.NET datagrid image based on SQL table value
one image if the value in my SQL table is true and another if it is
false. Here is my code.
<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false"
Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
absolute; TOP: 0px" runat="server"
BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
BackColor="#DEBA84" CellPadding="3"
AutoGenerateColumns="False" CellSpacing="2">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510"
BackColor="#F7DFB5"></FooterStyle>
<Columns>
</asp:BoundColumn>
<asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Check or X">
<ItemTemplate>
<img src='\Check.gif'>
</ItemTemplate>
</asp:TemplateColumn
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML
I want to show the 'Check.gif' if an SQL table value is True or
'x.gif' if it is false.
Thaks for any help, This ASP.NET is kicking my butt.Hi Rob,
Just jam a little
<IMG src='<%#iif(DataBinder.Eval(Container,
"DataItem.Boolean"),"Check.gif","x.gif") %>'
in there and you should be okay.
BTW, I had some problems with your markup. My fixed version is below.
Does this help?
Ken
Microsoft MVP [ASP.NET]
Toronto
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" runat="server" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px"
BackColor="#DEBA84" CellPadding="3" AutoGenerateColumns="False"
CellSpacing="2">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510" BackColor="#F7DFB5"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Check or X">
<ItemTemplate>
<IMG src='<%#iif(DataBinder.Eval(Container,
"DataItem.Boolean"),"Check.gif","x.gif") %>'>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML
"Rob Rogers" <rob@.natltc.com> wrote in message
news:7ee34208.0407141234.18d2abdd@.posting.google.c om...
>I have an ASP.NET datagrid that loads an image. I would like to load
> one image if the value in my SQL table is true and another if it is
> false. Here is my code.
> <%@. Page Language="vb" AutoEventWireup="false"
> Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
> <meta name="vs_defaultClientScript" content="VBScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
> absolute; TOP: 0px" runat="server"
> BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
> BackColor="#DEBA84" CellPadding="3"
> AutoGenerateColumns="False" CellSpacing="2">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#738A9C"></SelectedItemStyle>
> <ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#A55129"></HeaderStyle>
> <FooterStyle ForeColor="#8C4510"
> BackColor="#F7DFB5"></FooterStyle>
> <Columns>
> </asp:BoundColumn>
> <asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
> <ItemStyle Width="150px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Check or X">
> <ItemTemplate>
> <img src='\Check.gif'>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> </Columns>
> <PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
> Mode="NumericPages"></PagerStyle>
> </asp:DataGrid>
> </form>
> </body>
> </HTML>
> I want to show the 'Check.gif' if an SQL table value is True or
> 'x.gif' if it is false.
> Thaks for any help, This ASP.NET is kicking my butt.
BTW, here's the code behind and data source that I used for that example.
"Boolean" is the name of the field as well as the type.
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
MyGrid.DataSource = CreateDataSource()
MyGrid.DataBind()
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("City", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Rob Rogers" <rob@.natltc.com> wrote in message
news:7ee34208.0407141234.18d2abdd@.posting.google.c om...
>I have an ASP.NET datagrid that loads an image. I would like to load
> one image if the value in my SQL table is true and another if it is
> false. Here is my code.
> <%@. Page Language="vb" AutoEventWireup="false"
> Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
> <meta name="vs_defaultClientScript" content="VBScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
> absolute; TOP: 0px" runat="server"
> BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
> BackColor="#DEBA84" CellPadding="3"
> AutoGenerateColumns="False" CellSpacing="2">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#738A9C"></SelectedItemStyle>
> <ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#A55129"></HeaderStyle>
> <FooterStyle ForeColor="#8C4510"
> BackColor="#F7DFB5"></FooterStyle>
> <Columns>
> </asp:BoundColumn>
> <asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
> <ItemStyle Width="150px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Check or X">
> <ItemTemplate>
> <img src='\Check.gif'>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> </Columns>
> <PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
> Mode="NumericPages"></PagerStyle>
> </asp:DataGrid>
> </form>
> </body>
> </HTML>
> I want to show the 'Check.gif' if an SQL table value is True or
> 'x.gif' if it is false.
> Thaks for any help, This ASP.NET is kicking my butt.
Thanks, Thats just what I needed.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Set ASPNET Version for Virtual Directory from C# App
n
our Win 2003 server machines. Using the System.DirectoryServices
DirectoryEntry class I have had very little trouble remotely creating and
configuring virtual directories on our servers. My problem is that I have
not found a way to remotely configure the version of ASPNET that will be use
d
by the application running in the virtual directories I create. We have a
mix of Web applications that require either version 1.1 or 2.0. The only wa
y
that I have found to manipulate ASPNET setting, other than doing it manually
through IIS Manager, is with the ASPNET_regiis.exe tool, which must be run o
n
the machine that is serving the virtual directory. Is there any way to set
a
virtual directory's ASPNET version remotely?
Mikere:
!> The only way that I have found to manipulate ASP.NET setting, other than
doing it
!> manually through IIS Manager, is with the ASPNET_regiis.exe tool, which m
ust be
!> run on the machine that is serving the virtual directory.
Right...
re:
!> Is there any way to set a virtual directory's ASP.NET version remotely?
Not that I know of.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"mikes" <mikes@.discussions.microsoft.com> wrote in message news:8F4530DF-4CAA-4A93-A19E-53B
AECAF5432@.microsoft.com...
>I am writing a C# Windows Application that will create virtual directories
on
> our Win 2003 server machines. Using the System.DirectoryServices
> DirectoryEntry class I have had very little trouble remotely creating and
> configuring virtual directories on our servers. My problem is that I have
> not found a way to remotely configure the version of ASPNET that will be u
sed
> by the application running in the virtual directories I create. We have a
> mix of Web applications that require either version 1.1 or 2.0. The only
way
> that I have found to manipulate ASPNET setting, other than doing it manual
ly
> through IIS Manager, is with the ASPNET_regiis.exe tool, which must be run
on
> the machine that is serving the virtual directory. Is there any way to se
t a
> virtual directory's ASPNET version remotely?
> Mike
Set ASPNET Version for Virtual Directory from C# App
our Win 2003 server machines. Using the System.DirectoryServices
DirectoryEntry class I have had very little trouble remotely creating and
configuring virtual directories on our servers. My problem is that I have
not found a way to remotely configure the version of ASPNET that will be used
by the application running in the virtual directories I create. We have a
mix of Web applications that require either version 1.1 or 2.0. The only way
that I have found to manipulate ASPNET setting, other than doing it manually
through IIS Manager, is with the ASPNET_regiis.exe tool, which must be run on
the machine that is serving the virtual directory. Is there any way to set a
virtual directory's ASPNET version remotely?
Mikere:
!The only way that I have found to manipulate ASP.NET setting, other than doing it
!manually through IIS Manager, is with the ASPNET_regiis.exe tool, which must be
!run on the machine that is serving the virtual directory.
Right...
re:
!Is there any way to set a virtual directory's ASP.NET version remotely?
Not that I know of.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"mikes" <mikes@.discussions.microsoft.comwrote in message news:8F4530DF-4CAA-4A93-A19E-53BAECAF5432@.microsoft.com...
Quote:
Originally Posted by
>I am writing a C# Windows Application that will create virtual directories on
our Win 2003 server machines. Using the System.DirectoryServices
DirectoryEntry class I have had very little trouble remotely creating and
configuring virtual directories on our servers. My problem is that I have
not found a way to remotely configure the version of ASPNET that will be used
by the application running in the virtual directories I create. We have a
mix of Web applications that require either version 1.1 or 2.0. The only way
that I have found to manipulate ASPNET setting, other than doing it manually
through IIS Manager, is with the ASPNET_regiis.exe tool, which must be run on
the machine that is serving the virtual directory. Is there any way to set a
virtual directory's ASPNET version remotely?
>
Mike
Set Asp.Net web control ID
Can someone tell me where can I find a list of the characters which I
can use in a web control ID?
Can I for example do:
MyLabel.ID = "Namespace#Control_Type"
Thanks,
Miguelshould be a legal xml id. (note: leading special chars are not allowed - ms
breaks this rule)
reg expression: [A-Za-z][A-Za-z0-9:_.-]*
if the id is used with a runat server, then it needs to be a valid .net
identifier.
-- bruce (sqlwork.com)
"shapper" <mdmoura@.gmail.com> wrote in message
news:1161701364.541401.15700@.k70g2000cwa.googlegroups.com...
> Hello,
> Can someone tell me where can I find a list of the characters which I
> can use in a web control ID?
> Can I for example do:
> MyLabel.ID = "Namespace#Control_Type"
> Thanks,
> Miguel
>
Set Asp.Net web control ID
Hello,
Can someone tell me where can I find a list of the characters which I can use in a web control ID?
Can I for example do:
MyLabel.ID = "Namespace#Control_Type"
Thanks,
Miguel
If you want to be safe, stick with letters and numbers (starting with a letter). Why would you need to worry about other characters?
System.Web.UI documentation for the Control.ID property states only this:
Including spaces in this property will cause an ASP.NET page parser error.
Just for fun, I created 256 labels, each using 1 of the ASCII characters:
for (Int32 counter = 0; counter <= 255; counter++)
{
try
{
Label lbl = new Label();
lbl.ID = "test_ " + Convert.ToChar(counter) + "test";
lbl.Text = "My ID is '" + lbl.ID + "'<br>";
Controls.Add(lbl);
}
catch
{
Label lbl = new Label();
lbl.Text = "ERROR USING CHARACTER '" + Convert.ToChar(counter) + "'<br>";
Controls.Add(lbl);
}
}
It generated no errors. So, I assume you can use any characters you want.
However, you may not use spaces if you declare the label in your HTML markup. For example, this throws an error:
<asp:Label ID="test test" runat="server" />
You, sir, have too much time on your hands. I envy you your four seasons...
Actually, that's a nice little demo, but you probably should consider a few more things. First off, I'd bet that there are other characters that the compiler doesn't like in markup (though of course I'm just assuming). Second, what happens when these controls need to be picked up on postback, or -- more likely to cause a problem -- accessed by client-side code? If nothing else, using chars like underscores, dollar signs, pound signs, and dots are going to confuse the heck out of anyone in the rendered HTML trying to tell what belongs to the control and what part is from the naming container.
Cheers,
Set Asp.Net web control ID
Can someone tell me where can I find a list of the characters which I
can use in a web control ID?
Can I for example do:
MyLabel.ID = "Namespace#Control_Type"
Thanks,
Miguelshould be a legal xml id. (note: leading special chars are not allowed - ms
breaks this rule)
reg expression: [A-Za-z][A-Za-z0-9:_.-]*
if the id is used with a runat server, then it needs to be a valid .net
identifier.
-- bruce (sqlwork.com)
"shapper" <mdmoura@.gmail.comwrote in message
news:1161701364.541401.15700@.k70g2000cwa.googlegro ups.com...
Quote:
Originally Posted by
Hello,
>
Can someone tell me where can I find a list of the characters which I
can use in a web control ID?
>
Can I for example do:
>
MyLabel.ID = "Namespace#Control_Type"
>
Thanks,
>
Miguel
>
Thursday, March 29, 2012
SET DATEFIRST and ASP.NET
My scenario is that I am writing and application on a server which host
several ASP.NET applications. In my application I would like to use a
function which relies on a custom function which unfortunately is dependent
on the SQL Server's SET DATEFIRST command which sets the first day of the
week for the current session.
The ASPNET account is solely responsible for opening and closing SQL
Connections for example, if I want data from a view, I run a function which
opens the connection gets the data and then closes it. If I issue a SET
DATEFIRST in one function and dont in another, will it get the default in
the second because I closed down the connection. >?
--
GoofyActually, while waiting I have done an experiement. The logic holds true.
Once the connection under which the SET DATEFIRST is used is closed, when a
new connection is re-opened, the default is restored so you can use this
independent of anyone else.
"Goofy" <me@.mine.comwrote in message
news:udxrRrJCHHA.204@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
Hi Everyone,
>
My scenario is that I am writing and application on a server which host
several ASP.NET applications. In my application I would like to use a
function which relies on a custom function which unfortunately is
dependent on the SQL Server's SET DATEFIRST command which sets the first
day of the week for the current session.
>
The ASPNET account is solely responsible for opening and closing SQL
Connections for example, if I want data from a view, I run a function
which opens the connection gets the data and then closes it. If I issue a
SET DATEFIRST in one function and dont in another, will it get the default
in the second because I closed down the connection. >?
>
>
>
>
--
Goofy
>
Wednesday, March 28, 2012
SET DATEFIRST and ASP.NET
My scenario is that I am writing and application on a server which host
several ASP.NET applications. In my application I would like to use a
function which relies on a custom function which unfortunately is dependent
on the SQL Server's SET DATEFIRST command which sets the first day of the
w
The ASPNET account is solely responsible for opening and closing SQL
Connections for example, if I want data from a view, I run a function which
opens the connection gets the data and then closes it. If I issue a SET
DATEFIRST in one function and dont in another, will it get the default in
the second because I closed down the connection. >?
GoofyActually, while waiting I have done an experiement. The logic holds true.
Once the connection under which the SET DATEFIRST is used is closed, when a
new connection is re-opened, the default is restored so you can use this
independent of anyone else.
"Goofy" <me@.mine.com> wrote in message
news:udxrRrJCHHA.204@.TK2MSFTNGP04.phx.gbl...
> Hi Everyone,
> My scenario is that I am writing and application on a server which host
> several ASP.NET applications. In my application I would like to use a
> function which relies on a custom function which unfortunately is
> dependent on the SQL Server's SET DATEFIRST command which sets the first
> day of the w
> The ASPNET account is solely responsible for opening and closing SQL
> Connections for example, if I want data from a view, I run a function
> which opens the connection gets the data and then closes it. If I issue a
> SET DATEFIRST in one function and dont in another, will it get the default
> in the second because I closed down the connection. >?
>
>
> --
> Goofy
>
Monday, March 26, 2012
Set file name returned from ASP.NET page by URL
I have an .aspx page which returns an image. This page takes some GET
parameters, so URL looks like this:
http://localhost/page.aspx?id=1234
Now, when the user click this link, I want that his browser would receive
picture with some good looking name, like image1.jpg.
How to do this within ASP.NET code ?..
--
Pawe
www.DATAX.plWrite an HTTPHandler. Using the Handler, you can make a request for an image
file and get back whatever the handler returns. For example,
http://localhost/image1.jpg?id=1234
would return an image named "image1.jpg" - which could be anything you
generate via your Handler.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"pawel" <pawel.zarzycki@.interia.pl> wrote in message
news:#1SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I have an .aspx page which returns an image. This page takes some GET
> parameters, so URL looks like this:
> http://localhost/page.aspx?id=1234
> Now, when the user click this link, I want that his browser would receive
> picture with some good looking name, like image1.jpg.
> How to do this within ASP.NET code ?..
> --
> Pawe
> www.DATAX.pl
Thanks for the answer.
Can you shortly tell me what exactly is that HTTPHandler ?.. I cant find
such topic in MSDN.
Paul
"Kevin Spencer" <kevin@.takempis.com> wrote in message
news:%23PRm1$B7DHA.2764@.TK2MSFTNGP09.phx.gbl...
> Write an HTTPHandler. Using the Handler, you can make a request for an
image
> file and get back whatever the handler returns. For example,
> http://localhost/image1.jpg?id=1234
> would return an image named "image1.jpg" - which could be anything you
> generate via your Handler.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
> "pawel" <pawel.zarzycki@.interia.pl> wrote in message
> news:#1SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> > Hi!
> > I have an .aspx page which returns an image. This page takes some GET
> > parameters, so URL looks like this:
> > http://localhost/page.aspx?id=1234
> > Now, when the user click this link, I want that his browser would
receive
> > picture with some good looking name, like image1.jpg.
> > How to do this within ASP.NET code ?..
> > --
> > Pawe
> > www.DATAX.pl
You might try something like this:
Response.Clear();
Response.AddHeader("Content-Disposition","inline;filename=image1.jpg");
Response.WriteFile("myfile.jpg");
Here's more info:
http://msdn.microsoft.com/library/d...tefiletopic.asp
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com
"pawel" <pawel.zarzycki@.interia.pl> wrote in message
news:%231SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I have an .aspx page which returns an image. This page takes some GET
> parameters, so URL looks like this:
> http://localhost/page.aspx?id=1234
> Now, when the user click this link, I want that his browser would receive
> picture with some good looking name, like image1.jpg.
> How to do this within ASP.NET code ?..
> --
> Pawe
> www.DATAX.pl
Sure. An HttpHandler is a class that handles HTTP requests. In ASP.Net a
Page class, for example, is the default HttpHandler for files with a .aspx
extension. You can map different file extensions to different HttpHandlers
in ASP.Net. What happens is, when the web server receives a request for a
file, it looks in its configuration to find out whether a special
HttpHandler has been designated for that file extension. ASP.Net provides
the HttpHandler class to extend the functionality of ASP.net to be able to
handle requests for other file types (extensions). In IIS, you make ASP.Net
the HttpHandler for the type of file that you desire, and use the web.config
file for your web to identify what DLL (Class Library) is used to handle
specific file extensions.
The HttpHandler is a clsss that handles the request. It has access to the
same HttpContext (Request, Response, Cookies, Session, Application, Server,
etc) that the Page class does.
For more detailed information, see:
http://msdn.microsoft.com/library/d...ttphandlers.asp
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"pawel" <pawel.zarzycki@.interia.pl> wrote in message
news:uLuTwUC7DHA.1052@.TK2MSFTNGP12.phx.gbl...
> Thanks for the answer.
> Can you shortly tell me what exactly is that HTTPHandler ?.. I cant find
> such topic in MSDN.
> Paul
> "Kevin Spencer" <kevin@.takempis.com> wrote in message
> news:%23PRm1$B7DHA.2764@.TK2MSFTNGP09.phx.gbl...
> > Write an HTTPHandler. Using the Handler, you can make a request for an
> image
> > file and get back whatever the handler returns. For example,
> > http://localhost/image1.jpg?id=1234
> > would return an image named "image1.jpg" - which could be anything you
> > generate via your Handler.
> > --
> > HTH,
> > Kevin Spencer
> > .Net Developer
> > Microsoft MVP
> > Big things are made up
> > of lots of little things.
> > "pawel" <pawel.zarzycki@.interia.pl> wrote in message
> > news:#1SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> > > Hi!
> > > I have an .aspx page which returns an image. This page takes some GET
> > > parameters, so URL looks like this:
> > > http://localhost/page.aspx?id=1234
> > > Now, when the user click this link, I want that his browser would
> receive
> > > picture with some good looking name, like image1.jpg.
> > > How to do this within ASP.NET code ?..
> > > > --
> > > Pawe
> > > www.DATAX.pl
> >
Saturday, March 24, 2012
set focus in a ASP.NET webpage
I would like to know if it is possible in ASP.NET to set the focus to a
control. I would like to make it possible for users to fill in a form. The
form contains textboxes and dropdownlists. When the user makes a selection
in a dropdownlist, certain default-values in textboxes are set. I use the
AutoPostBack=True property in the dropdownlist, but after the page has been
transferred back to the server, the control has also lost it's focus. That's
annoying for users, especially when there are more than 1 dropdownlists that
postback to the server.
Greetings,
Christian.The most reliable way is client side javascript:
MyControl.focus();
Here's more info:
http://wp.netscape.com/eng/mozilla/...f_f-g.htm#59872
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com
"Remco Groot Beumer" <info@.rgbplus.nl> wrote in message
news:bp0k6q$pao$1@.news4.tilbu1.nb.home.nl...
> Hello,
> I would like to know if it is possible in ASP.NET to set the focus to a
> control. I would like to make it possible for users to fill in a form. The
> form contains textboxes and dropdownlists. When the user makes a selection
> in a dropdownlist, certain default-values in textboxes are set. I use the
> AutoPostBack=True property in the dropdownlist, but after the page has
been
> transferred back to the server, the control has also lost it's focus.
That's
> annoying for users, especially when there are more than 1 dropdownlists
that
> postback to the server.
> Greetings,
> Christian.
When an ASP.NET page is processing its code, it's doing so on the server.
And, that is well before the client actually receives the page.
Setting focus should really be done with traditional client-side scripting
(JavaScript).
"Remco Groot Beumer" <info@.rgbplus.nl> wrote in message
news:bp0k6q$pao$1@.news4.tilbu1.nb.home.nl...
> Hello,
> I would like to know if it is possible in ASP.NET to set the focus to a
> control. I would like to make it possible for users to fill in a form. The
> form contains textboxes and dropdownlists. When the user makes a selection
> in a dropdownlist, certain default-values in textboxes are set. I use the
> AutoPostBack=True property in the dropdownlist, but after the page has
been
> transferred back to the server, the control has also lost it's focus.
That's
> annoying for users, especially when there are more than 1 dropdownlists
that
> postback to the server.
> Greetings,
> Christian.
Set focus on the field (Form validation in ASP.NET)
I have a problem and really need your help. In my web page ASPX, I have
some text fields to accept data from users. I did form validation like this
:
<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION: absolute"
runat="server" Width="107px" BorderColor="Transparent"
autoPostback="true"
OnTextChanged="txtFUEL_ISSUED1_TextChanged"></asp:TextBox>
</td>
<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:CompareValidator id="CompareValidator1"
runat="server" Width="90px" ControlToValidate="txtFUEL_ISSUED1"
ForeColor="LightCoral" ErrorMessage="Please enter a number!"
Operator="DataTypeCheck" Type="Double"></asp:CompareValidator>
</td>
In the txtFUEL_ISSUED1_TextChanged, I checked if data on this field is valid
or not. If it's valid then I add this value in the TOTAL field. I'd to to
set focus on the next field when this data IS VALID, OR focus on this field
when data IS NOT valid . Can you help me ? Thanks in advanceI suggest you upgrade to ASP.NET 2.0, which has new features that satisfy
all your requests.
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"bienwell" <bienwell@.hotmail.com> wrote in message
news:%23O5W3po9FHA.476@.TK2MSFTNGP15.phx.gbl...
> Hi,
> I have a problem and really need your help. In my web page ASPX, I have
> some text fields to accept data from users. I did form validation like
> this :
> <td class="dataTD" style="HEIGHT: 30px" width="100">
> <asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION:
> absolute" runat="server" Width="107px" BorderColor="Transparent"
> autoPostback="true"
> OnTextChanged="txtFUEL_ISSUED1_TextChanged"></asp:TextBox>
> </td>
> <td class="dataTD" style="HEIGHT: 30px" width="100">
> <asp:CompareValidator id="CompareValidator1"
> runat="server" Width="90px" ControlToValidate="txtFUEL_ISSUED1"
> ForeColor="LightCoral" ErrorMessage="Please enter a number!"
> Operator="DataTypeCheck" Type="Double"></asp:CompareValidator>
> </td>
>
> In the txtFUEL_ISSUED1_TextChanged, I checked if data on this field is
> valid or not. If it's valid then I add this value in the TOTAL field. I'd
> to to set focus on the next field when this data IS VALID, OR focus on
> this field when data IS NOT valid . Can you help me ? Thanks in advance
>
Steve,
I have some questions:
1- There are some versions ASP.NET 2.0 from the www.asp.net web site :
a- .NET Framework 2.0 SDK x86,
b- .NET Framework Version 2.0 Redistributable Package (x86)
c- .NET Framework 2.0 SDK x64
d- .NET Framework Version 2.0 Redistributable Package x64 (64
Bit)
e- .NET Framework 2.0 SDK IA64
f- .NET Framework Version 2.0 Redistributable Package IA64
(64 Bit)
Which one do you suggest me to download ?
2- After downloading, do you think this code will work OR I should
change something ?
Sub txtFUEL_ISSUED1_TextChanged(sender As Object, e As EventArgs)
Dim strScript As String = "<script language=JavaScript>"
If IsNumeric(txtFUEL_ISSUED1.text) OR
txtFUEL_ISSUED1.text="" Then
Dim aValue as double=0.0
If IsNumeric(txtFUEL_ISSUED1.text) Then
aValue=CDBL(txtFUEL_ISSUED1.Text)
End If
' ADD the value to the TOTAL field
ViewState("FUEL_ISSUED_Total") =
ViewState("FUEL_ISSUED_Total") + aValue - ViewState("FUEL_ISSUED1")
txtFUEL_ISSUED_Total.text=FormatNumber(ViewState("FUEL_ISSUED_Total"),
2, , ,TriState.True)
ViewState("FUEL_ISSUED1") = aValue
strScript = strScript &
"document.form1.txtFUEL_ISSUED2.focus();" 'FOCUS on the next field
Else 'FOCUS on the current field
strScript = strScript &
"document.form1.txtFUEL_ISSUED1.focus();"
End If
strScript = strScript & "<" & "/script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If
End Sub
========================================
===========
"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
news:%23Tibhzt9FHA.1288@.TK2MSFTNGP09.phx.gbl...
>I suggest you upgrade to ASP.NET 2.0, which has new features that satisfy
>all your requests.
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
> "bienwell" <bienwell@.hotmail.com> wrote in message
> news:%23O5W3po9FHA.476@.TK2MSFTNGP15.phx.gbl...
>
If you have a 32-bit machine ( a standard Intel or AMD )...
If you want the very minimum necessary to run ASP.NET 2.0,
get .NET Framework Version 2.0 Redistributable Package (x86)
If you want the QuickStart Tutorials, extra tools *and* ASP.NET 2.0,
get .NET Framework 2.0 SDK x86
If you have a 64-bit machine, your choice may vary depending on the cpu.
The code you posted should run on any of the 5 choices.
Juan T. Llibre
ASP.NET.FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"bienwell" <bienwell@.hotmail.com> wrote in message news:%23KAB7j09FHA.1140@.tk2msftngp13.phx
.gbl...
> Steve,
> I have some questions:
> 1- There are some versions ASP.NET 2.0 from the www.asp.net web site
:
> a- .NET Framework 2.0 SDK x86,
> b- .NET Framework Version 2.0 Redistributable Package (x86)
> c- .NET Framework 2.0 SDK x64
> d- .NET Framework Version 2.0 Redistributable Package x64 (64
Bit)
> e- .NET Framework 2.0 SDK IA64
> f- .NET Framework Version 2.0 Redistributable Package IA64 (
64 Bit)
> Which one do you suggest me to download ?
>
> 2- After downloading, do you think this code will work OR I should cha
nge something ?
> Sub txtFUEL_ISSUED1_TextChanged(sender As Object, e As EventArgs)
> Dim strScript As String = "<script language=JavaScript>"
> If IsNumeric(txtFUEL_ISSUED1.text) OR txtFUEL_ISSUED1.tex
t="" Then
> Dim aValue as double=0.0
> If IsNumeric(txtFUEL_ISSUED1.text) Then
> aValue=CDBL(txtFUEL_ISSUED1.Text)
> End If
> ' ADD the value to the TOTAL field
> ViewState("FUEL_ISSUED_Total") = ViewState("FUEL_ISS
UED_Total") + aValue -
> ViewState("FUEL_ISSUED1")
> txtFUEL_ISSUED_Total.text=FormatNumber(ViewState("F
UEL_ISSUED_Total"), 2, ,
> ,TriState.True)
> ViewState("FUEL_ISSUED1") = aValue
> strScript = strScript & "document.form1.txtFUEL_ISS
UED2.focus();"
> 'FOCUS on the next field
> Else 'FOCUS on the current field
> strScript = strScript & "document.form1.txtFUEL_IS
SUED1.focus();"
> End If
> strScript = strScript & "<" & "/script>"
> If (Not Page.IsStartupScriptRegistered("clientScript")) Then
> Page.RegisterStartupScript("clientScript", strScript)
> End If
> End Sub
> ========================================
===========
> "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
> news:%23Tibhzt9FHA.1288@.TK2MSFTNGP09.phx.gbl...
Thank you very much for your advices.
bienwell
==============================
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:eZ$7KP19FHA.904@.TK2MSFTNGP09.phx.gbl...
> If you have a 32-bit machine ( a standard Intel or AMD )...
> If you want the very minimum necessary to run ASP.NET 2.0,
> get .NET Framework Version 2.0 Redistributable Package (x86)
>
> If you want the QuickStart Tutorials, extra tools *and* ASP.NET 2.0,
> get .NET Framework 2.0 SDK x86
> If you have a 64-bit machine, your choice may vary depending on the cpu.
> The code you posted should run on any of the 5 choices.
>
> Juan T. Llibre
> ASP.NET.FAQ : http://asp.net.do/faq/
> ASPNETFAQ.COM : http://www.aspnetfaq.com/
> Foros de ASP.NET en Espaol : http://asp.net.do/foros/
> ======================================
> "bienwell" <bienwell@.hotmail.com> wrote in message
> news:%23KAB7j09FHA.1140@.tk2msftngp13.phx.gbl...
>
>
>
Tuesday, March 13, 2012
Set selected node in Treeview control in ASP:NET 2.0 ? Anyone know this ?
Iam using Treeview control in asp.net 2.0. But have a problem.
I use NavigateUrl BUT then viewstate is lost when clicked on a link i
the menu. And the selected node is lost.
Then i have to set the selected node manually, how can i do it ? i have
tried but without luck :(
I have posted my menu code here.
namespace DayDream.Admin.UC
{
public partial class AdminMenu : DayDreamBaseUserControl
{
public string SelectedURL;
protected void Page_Load(object sender, EventArgs e)
{
DataBind();
}
protected void PopulateNode(Object sender, TreeNodeEventArgs e)
{
// Call the appropriate method to populate a node at a
particular level.
switch (e.Node.Depth)
{
case 0:
// Populate the first-level nodes.
PopulateTopLevelNodes(e.Node);
break;
case 1:
// Populate the second-level nodes.
PopulateChildern(e.Node);
break;
default:
// Do nothing.
break;
}
}
private void PopulateTopLevelNodes(TreeNode node)
{
DayDreamBasePage basePage = new DayDreamBasePage();
for (int x = 0; x <
basePage.GetAllPages().Tables[0].Rows.Count; x++)
{
if
(basePage.GetAllPages().Tables[0].Rows[x]["ParentPageID"].ToString().Length
<= 0)
{
TreeNode TopLevel = new TreeNode();
//TopLevel.NavigateUrl =
basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString() +
"?id=" + basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
TopLevel.NavigateUrl =
"../../"+basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString()
+ "?id=" +
basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
TopLevel.Text =
basePage.GetAllPages().Tables[0].Rows[x]["PageName"].ToString();
TopLevel.Value =
basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
// Add root node to TreeView
TopLevel.PopulateOnDemand = true;
TopLevel.SelectAction =
TreeNodeSelectAction.SelectExpand;
node.ChildNodes.Add(TopLevel);
}
}
}
private void PopulateChildern(TreeNode node)
{
DayDreamBasePage basePage = new DayDreamBasePage();
DataSet Childrens = new DataSet();
Childrens =
basePage.GetChildrenPages(Int32.Parse(node.Value)) ;
for (int y = 0; y < Childrens.Tables[0].Rows.Count; y++)
{
TreeNode newNode = new TreeNode();
newNode.NavigateUrl = "../../" +
Childrens.Tables[0].Rows[y]["Template"].ToString() + "?id=" +
Childrens.Tables[0].Rows[y]["PageID"].ToString();
newNode.Text =
Childrens.Tables[0].Rows[y]["PageName"].ToString();
newNode.Value =
Childrens.Tables[0].Rows[y]["PageID"].ToString();
// Set additional properties for the node.
newNode.SelectAction =
TreeNodeSelectAction.SelectExpand;
// Add the new node to the ChildNodes collection of the
parent node.
node.ChildNodes.Add(newNode);
DataSet ChildrensSub = new DataSet();
int ChildrensSubCount =
basePage.GetChildrenPages(Int32.Parse(newNode.Valu e)).Tables[0].Rows.Count;
if (ChildrensSubCount > 0)
{
PopulateChildern(newNode);
}
}
}
}
}
Thanks
JeppeOn Page_Load event you are not checking if Page isPostBack
If Not (Page.IsPostBack) {
DataBind();
}
Sandeep
"jesper_lofgren@.yahoo.se" wrote:
> Hello,
> Iam using Treeview control in asp.net 2.0. But have a problem.
> I use NavigateUrl BUT then viewstate is lost when clicked on a link i
> the menu. And the selected node is lost.
> Then i have to set the selected node manually, how can i do it ? i have
> tried but without luck :(
> I have posted my menu code here.
>
> namespace DayDream.Admin.UC
> {
> public partial class AdminMenu : DayDreamBaseUserControl
> {
> public string SelectedURL;
> protected void Page_Load(object sender, EventArgs e)
> {
> DataBind();
>
> }
> protected void PopulateNode(Object sender, TreeNodeEventArgs e)
> {
> // Call the appropriate method to populate a node at a
> particular level.
> switch (e.Node.Depth)
> {
> case 0:
> // Populate the first-level nodes.
> PopulateTopLevelNodes(e.Node);
> break;
> case 1:
> // Populate the second-level nodes.
> PopulateChildern(e.Node);
> break;
> default:
> // Do nothing.
> break;
> }
> }
>
> private void PopulateTopLevelNodes(TreeNode node)
> {
> DayDreamBasePage basePage = new DayDreamBasePage();
> for (int x = 0; x <
> basePage.GetAllPages().Tables[0].Rows.Count; x++)
> {
> if
> (basePage.GetAllPages().Tables[0].Rows[x]["ParentPageID"].ToString().Length
> <= 0)
> {
> TreeNode TopLevel = new TreeNode();
> //TopLevel.NavigateUrl =
> basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString() +
> "?id=" + basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
> TopLevel.NavigateUrl =
> "../../"+basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString()
> + "?id=" +
> basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
> TopLevel.Text =
> basePage.GetAllPages().Tables[0].Rows[x]["PageName"].ToString();
> TopLevel.Value =
> basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
> // Add root node to TreeView
> TopLevel.PopulateOnDemand = true;
> TopLevel.SelectAction =
> TreeNodeSelectAction.SelectExpand;
> node.ChildNodes.Add(TopLevel);
>
> }
> }
> }
>
> private void PopulateChildern(TreeNode node)
> {
> DayDreamBasePage basePage = new DayDreamBasePage();
> DataSet Childrens = new DataSet();
> Childrens =
> basePage.GetChildrenPages(Int32.Parse(node.Value)) ;
> for (int y = 0; y < Childrens.Tables[0].Rows.Count; y++)
> {
> TreeNode newNode = new TreeNode();
> newNode.NavigateUrl = "../../" +
> Childrens.Tables[0].Rows[y]["Template"].ToString() + "?id=" +
> Childrens.Tables[0].Rows[y]["PageID"].ToString();
> newNode.Text =
> Childrens.Tables[0].Rows[y]["PageName"].ToString();
> newNode.Value =
> Childrens.Tables[0].Rows[y]["PageID"].ToString();
> // Set additional properties for the node.
> newNode.SelectAction =
> TreeNodeSelectAction.SelectExpand;
> // Add the new node to the ChildNodes collection of the
> parent node.
> node.ChildNodes.Add(newNode);
> DataSet ChildrensSub = new DataSet();
> int ChildrensSubCount =
> basePage.GetChildrenPages(Int32.Parse(newNode.Valu e)).Tables[0].Rows.Count;
> if (ChildrensSubCount > 0)
> {
> PopulateChildern(newNode);
> }
> }
> }
>
> }
> }
>
> Thanks
> Jeppe
>