Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Saturday, March 31, 2012

set ASP.NET datagrid image based on SQL table value

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.
<%@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

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.

<%@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 asp:tablecell text from javascript

on my form i got a table with cell like this:
<asp:TableCell ID="tdNavigation_Sub" Runat="server"></asp:TableCell>
To set the text that goes in here from the code behind is easy... just:
protected TableCell tdNavigation_Sub; and tdNavigation_Sub.Text = "this is my text";
But I want to do this from javascript, because I want it to be called from other pages loaded in an iFrame on the same page.
On this kids, I will just call "parent.myscript("blah blah");"...easy

but i canot get the javascript on the main form right...so pls help?
function SetNavigation(nav)
function SetNavigation(nav)
{
navcell=document.getElementById("tdNavigation_Sub");
navcell.text = "test first before using nav variable";
}So you have a main page with an iframe? The iframe contains the tablecells right?
Are you getting a javascript error?
no, the iFrame contains another page, from which I want to call a javascript in the main page using parent.myscript("...
I created a test and got it to work. Let me know if this is what you are looking for...

1-Create a separate .js file...

function changecell()
{
var mycell;
mycell=parent.document.getElementById("tablecell_changeMe");
mycell.innerHTML='this is madness';
}


2-Create a file that will be your iframe...

<%@. Page Language="vb" AutoEventWireup="false" Codebehind="iframe1.aspx.vb" Inherits="TableCellExample.iframe1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>iframe1</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="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" src="http://pics.10026.com/?src=JScript1.js"></script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 103; LEFT: 32px; WIDTH: 208px; POSITION: absolute; TOP: 40px; HEIGHT: 24px"
onclick="changecell()" type="button" value="Button Test from Iframe">
</form>
</body>
</HTML>

3-Create the main page and add the iframe tag...

<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="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" src="http://pics.10026.com/?src=JScript1.js">
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Table id="Table1" style="Z-INDEX: 100; LEFT: 32px; POSITION: absolute; TOP: 32px" runat="server"
Width="208px" Height="120px">
<asp:TableRow></asp:TableRow>
<asp:TableRow></asp:TableRow>
<asp:TableRow>
<asp:TableCell ID="tablecell_changeMe">test cell 1</asp:TableCell>
<asp:TableCell>test cell 2</asp:TableCell>
<asp:TableCell>test cell 3</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br>
<br>
<!-- Okay here is our iframe -->
<iframe id="myiframe" src="http://pics.10026.com/?src=iframe1.aspx" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 392px; POSITION: absolute; TOP: 184px; HEIGHT: 176px">
</iframe><INPUT style="Z-INDEX: 103; LEFT: 32px; WIDTH: 72px; POSITION: absolute; TOP: 400px; HEIGHT: 24px"
type="button" value="Button" onclick="changecell()">
</form>
</body>
</HTML>

Let me know if you have problems with the test above.
Maybe all you needed changed was...

navcell=parent.document.getElementById("tdNavigation_Sub");
Thanks!

Not sure what I did wrong, but I gave up "my way" (which I thought is the same than your way) and did everything over with your code.
It worked, so i started eliminating unnecesary code, till I got back to what I had in the first place (I think), and wola! .. it worked still.

Thanks again mate!
no problem, glad it worked. :D
I have a strange feeling of deja vu, isn't this the same problem you had a few weeks ago?
Yeah..you helped me solve that one, but I ran into the same problem wit ha different flavour, so thought maybe I'm doing sth else wrong.

Just been using JScript a lot lately...I should get a book and work through it, but TIME man!!!

Thursday, March 29, 2012

Set Class Instance to Nothing During Instantiation?

I'm creating a class (using VB.NET) that must read data from a
database table during instantiation. If the data cannot be read
(connection problem, etc.), I want the instantiation to fail such that
the following "If" statement will evaluate to True:

Dim objGribble as New cGribble()
If objGribble Is Nothing Then ...

What code in the class's constructor (Sub New) would make that happen?You can't. You're constructor can throw an exception...which how you
should do it anyways. if that isn't satisfactory, you can wrap your
constructor call in a static property of your class:

dim objGribble as cGribble = cGribble.CreateInstance()
if objGriggle is nothing then..

where CreateInstance() looks something like:

Public shared Property CreateInstance() as CGribble
get
try
return new cGribble()
catch ex as YourCustomException 'for the love of god don't
swallow this exception
return null
end try
end get
end property

karl

"Jeff Carver" <jeff_carver@.hotmail.com> wrote in message
news:b62a6c2a.0408240258.302ab414@.posting.google.c om...
> I'm creating a class (using VB.NET) that must read data from a
> database table during instantiation. If the data cannot be read
> (connection problem, etc.), I want the instantiation to fail such that
> the following "If" statement will evaluate to True:
> Dim objGribble as New cGribble()
> If objGribble Is Nothing Then ...
> What code in the class's constructor (Sub New) would make that happen?
Or, here's another method. Do a Web Search on "Factory Pattern"

You can implement it kinda like this

Public Class MyClass
Private Sub New()
' You can not directly instantiate this class
End Sub

Public Shared Function GetInstance(param1 as string, param2 as integer,
...) as MyClass
Dim result as new MyClass 'Since its private, the constructor can be
called inside the class
''' Code to possibly load from database
If CanLoadFromDB then
Return result
Else
Return Nothing
End If
End Function

End Class

Instead of :
Dim objGribble as New cGribble()
If objGribble Is Nothing Then ...

You'll end up with:
Dim objGribble as cGribble = cGribble.GetInstance()
If objGribble Is Nothing Then ...

Now this will work. If you're totally set about this type of approach, then
go for it, dude! However, if you use the approach that Carl mentioned, you
do get one major benefit. All you know from this approach is that the class
can not be created. Was it because of a database error? Was it because of
a division Error? What about Solar Flares? If you throw an exception
inside of the constructor, you can catch it and inform the user about the
error, as it was thrown, as opposed to the assumption that it was error "X".

"Jeff Carver" <jeff_carver@.hotmail.com> wrote in message
news:b62a6c2a.0408240258.302ab414@.posting.google.c om...
> I'm creating a class (using VB.NET) that must read data from a
> database table during instantiation. If the data cannot be read
> (connection problem, etc.), I want the instantiation to fail such that
> the following "If" statement will evaluate to True:
> Dim objGribble as New cGribble()
> If objGribble Is Nothing Then ...
> What code in the class's constructor (Sub New) would make that happen?
Thanks, Karl and David. These are very interesting approaches, and
they're definitely going into my snippet file! I'm not sure yet which
I'll use for this current project, but I imagine I'll be using them
both in different situations in the future.

Set Class Instance to Nothing During Instantiation?

I'm creating a class (using VB.NET) that must read data from a
database table during instantiation. If the data cannot be read
(connection problem, etc.), I want the instantiation to fail such that
the following "If" statement will evaluate to True:
Dim objGribble as New cGribble()
If objGribble Is Nothing Then ...
What code in the class's constructor (Sub New) would make that happen?You can't. You're constructor can throw an exception...which how you
should do it anyways. if that isn't satisfactory, you can wrap your
constructor call in a static property of your class:
dim objGribble as cGribble = cGribble.CreateInstance()
if objGriggle is nothing then..
where CreateInstance() looks something like:
Public shared Property CreateInstance() as CGribble
get
try
return new cGribble()
catch ex as YourCustomException 'for the love of god don't
swallow this exception
return null
end try
end get
end property
karl
"Jeff Carver" <jeff_carver@.hotmail.com> wrote in message
news:b62a6c2a.0408240258.302ab414@.posting.google.com...
> I'm creating a class (using VB.NET) that must read data from a
> database table during instantiation. If the data cannot be read
> (connection problem, etc.), I want the instantiation to fail such that
> the following "If" statement will evaluate to True:
> Dim objGribble as New cGribble()
> If objGribble Is Nothing Then ...
> What code in the class's constructor (Sub New) would make that happen?
Or, here's another method. Do a Web Search on "Factory Pattern"
You can implement it kinda like this
Public Class MyClass
Private Sub New()
' You can not directly instantiate this class
End Sub
Public Shared Function GetInstance(param1 as string, param2 as integer,
...) as MyClass
Dim result as new MyClass 'Since its private, the constructor can be
called inside the class
''' Code to possibly load from database
If CanLoadFromDB then
Return result
Else
Return Nothing
End If
End Function
End Class
Instead of :
Dim objGribble as New cGribble()
If objGribble Is Nothing Then ...
You'll end up with:
Dim objGribble as cGribble = cGribble.GetInstance()
If objGribble Is Nothing Then ...
Now this will work. If you're totally set about this type of approach, then
go for it, dude! However, if you use the approach that Carl mentioned, you
do get one major benefit. All you know from this approach is that the class
can not be created. Was it because of a database error? Was it because of
a division Error? What about Solar Flares? If you throw an exception
inside of the constructor, you can catch it and inform the user about the
error, as it was thrown, as opposed to the assumption that it was error "X".
"Jeff Carver" <jeff_carver@.hotmail.com> wrote in message
news:b62a6c2a.0408240258.302ab414@.posting.google.com...
> I'm creating a class (using VB.NET) that must read data from a
> database table during instantiation. If the data cannot be read
> (connection problem, etc.), I want the instantiation to fail such that
> the following "If" statement will evaluate to True:
> Dim objGribble as New cGribble()
> If objGribble Is Nothing Then ...
> What code in the class's constructor (Sub New) would make that happen?
Thanks, Karl and David. These are very interesting approaches, and
they're definitely going into my snippet file! I'm not sure yet which
I'll use for this current project, but I imagine I'll be using them
both in different situations in the future.

Set connection string of table adapter dynamically

Hello .
I am stucked with the following problem and hope you can help me :
- My ASP.NET 2.0 application has one master database .
- This master database has a Databases table with list of children
databases .
- All children databases have the same schema ( only the data is
different ) .
My application connects to the Master database first (
connection String of this database should be read from the C:\WINDOWS
\XXX.INI file).
Login web page will present drop-down list of sub-databases ( which
will be
retrieved from the Master database ) and then will connect to
specified sub-database and will display data
from this database in a GridView .
I would like to be able to bind this GridView to the Data Source
Objects , to edit all columns during design time , and to set the
connection string of corresponding table adapter programmatically
during run-time .
How can I do this ?
I found several references to the connection string ( for example ,
via appSettings) , but I got an error message that this is read only
parameter .
Please advice .
Thanks in advance for your help ,
Orit Chanukov .Keep it in a session variable.
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Orit" <oritc123@.gmail.com> wrote in message
news:1183138531.120152.59480@.a26g2000pre.googlegroups.com...
> Hello .
> I am stucked with the following problem and hope you can help me :
> - My ASP.NET 2.0 application has one master database .
> - This master database has a Databases table with list of children
> databases .
> - All children databases have the same schema ( only the data is
> different ) .
> My application connects to the Master database first (
> connection String of this database should be read from the C:\WINDOWS
> \XXX.INI file).
> Login web page will present drop-down list of sub-databases ( which
> will be
> retrieved from the Master database ) and then will connect to
> specified sub-database and will display data
> from this database in a GridView .
> I would like to be able to bind this GridView to the Data Source
> Objects , to edit all columns during design time , and to set the
> connection string of corresponding table adapter programmatically
> during run-time .
> How can I do this ?
> I found several references to the connection string ( for example ,
> via appSettings) , but I got an error message that this is read only
> parameter .
> Please advice .
> Thanks in advance for your help ,
> Orit Chanukov .
>

Set connection string of table adapter dynamically

Hello .

I am stucked with the following problem and hope you can help me :

-My ASP.NET 2.0 application has one master database .
-This master database has a Databases table with list of children
databases .
-All children databases have the same schema ( only the data is
different ) .
My application connects to the Master database first (
connection String of this database should be read from the C:\WINDOWS
\XXX.INI file).
Login web page will present drop-down list of sub-databases ( which
will be
retrieved from the Master database ) and then will connect to
specified sub-database and will display data
from this database in a GridView .
I would like to be able to bind this GridView to the Data Source
Objects , to edit all columns during design time , and to set the
connection string of corresponding table adapter programmatically
during run-time .
How can I do this ?
I found several references to the connection string ( for example ,
via appSettings) , but I got an error message that this is read only
parameter .
Please advice .
Thanks in advance for your help ,
Orit Chanukov .Keep it in a session variable.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Orit" <oritc123@.gmail.comwrote in message
news:1183138531.120152.59480@.a26g2000pre.googlegro ups.com...

Quote:

Originally Posted by

Hello .
>
I am stucked with the following problem and hope you can help me :
>
- My ASP.NET 2.0 application has one master database .
- This master database has a Databases table with list of children
databases .
- All children databases have the same schema ( only the data is
different ) .
My application connects to the Master database first (
connection String of this database should be read from the C:\WINDOWS
\XXX.INI file).
Login web page will present drop-down list of sub-databases ( which
will be
retrieved from the Master database ) and then will connect to
specified sub-database and will display data
from this database in a GridView .
I would like to be able to bind this GridView to the Data Source
Objects , to edit all columns during design time , and to set the
connection string of corresponding table adapter programmatically
during run-time .
How can I do this ?
I found several references to the connection string ( for example ,
via appSettings) , but I got an error message that this is read only
parameter .
Please advice .
Thanks in advance for your help ,
Orit Chanukov .
>

Monday, March 26, 2012

Set field to null

I am trying to set a field in a sql server table to null if the user hits a certain button.

How can I set it to DBNull?

I have tried the following but It doesnt work.

Dim updateSOrder As String = "Update SOrders set confirm_id = @dotnet.itags.org.confirmId where SOrder ='" & lblConfirmOrder.Text & "'"

Dim SaveDelete As SqlCommand
SaveDelete = New SqlCommand(updateSOrder, oConnection)

Dim blank As DBNull
SaveDelete.Parameters.Add(New SqlParameter("@dotnet.itags.org.ConfirmId", SqlDbType.NVarChar, 40))
SaveDelete.Parameters("@dotnet.itags.org.ConfirmId").Value = blank

SaveDelete.ExecuteNonQuery()

You may try this:

SaveDelete.Parameters("@.ConfirmId").Value = DBNull.Value

Thursday, March 22, 2012

Set html table width at run time (in code)

Hi
How can I get a html control in my code?
I have a html table that I want the width is defined in code at run time,
i.e., I have this table and I have a datagrid. This datagrid have a variable
width because the number of columns depends of something that I have (that
is not important for this). Now, what I want is that the html table have
always the same width of my datagrid because of alignment of both.
NOTE: I must have (and want) the datagrid width variable and not fixed
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
rucaset its attribute runat=server, but you'll probably still have problems
while tables align width depending on its content... You can hardly create
different tables with same width. The only chance is when content never
exceedes desired table (or better said cell) width.
RobertK
{ Clever? No just smart. }
"ruca" <ruuca@.iol.pt> wrote in message
news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> Hi
> How can I get a html control in my code?
> I have a html table that I want the width is defined in code at run time,
> i.e., I have this table and I have a datagrid. This datagrid have a
variable
> width because the number of columns depends of something that I have (that
> is not important for this). Now, what I want is that the html table have
> always the same width of my datagrid because of alignment of both.
> NOTE: I must have (and want) the datagrid width variable and not fixed
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>
Thanks
Now, how can I get the widht value at run time of a datagrid?
I have this:
Dim dgPx As Unit
dgPx = myDataGrid.Width()
But dgPx.Value does not have the value of the grid after binding grid.
Can you help?
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca
"Robert Koritnik" <robert.koritnik.removethis@.avtenta.si> escreveu na
mensagem news:%23hnurAxbEHA.2816@.TK2MSFTNGP11.phx.gbl...
> set its attribute runat=server, but you'll probably still have problems
> while tables align width depending on its content... You can hardly create
> different tables with same width. The only chance is when content never
> exceedes desired table (or better said cell) width.
> --
> RobertK
> { Clever? No just smart. }
> "ruca" <ruuca@.iol.pt> wrote in message
> news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
time,
> variable
(that
>
You will have to set that. I told you in my first answer this is a tough
one. The best suggestion I could give you is to put both (table and
Datagrid) inside another table set both control's width to 100%. They would
perfectly align and everything will depend on the width of the containing
table cell.
And you probably won't have to wory about widths of both parts of the
page... Or better said tables, while a datagris is also a table.
RobertK
{ Clever? No just smart. }
"ruca" <ruuca@.iol.pt> wrote in message
news:ekMCZTxbEHA.1048@.tk2msftngp13.phx.gbl...
> Thanks
> Now, how can I get the widht value at run time of a datagrid?
> I have this:
> Dim dgPx As Unit
> dgPx = myDataGrid.Width()
> But dgPx.Value does not have the value of the grid after binding grid.
> Can you help?
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
> "Robert Koritnik" <robert.koritnik.removethis@.avtenta.si> escreveu na
> mensagem news:%23hnurAxbEHA.2816@.TK2MSFTNGP11.phx.gbl...
create
> time,
> (that
have
>
One doesn't do this sort of things in the code. Put both the table and the
grid in another table as it's been suggested in another reply.
Eliyahu
"ruca" <ruuca@.iol.pt> wrote in message
news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> Hi
> How can I get a html control in my code?
> I have a html table that I want the width is defined in code at run time,
> i.e., I have this table and I have a datagrid. This datagrid have a
variable
> width because the number of columns depends of something that I have (that
> is not important for this). Now, what I want is that the html table have
> always the same width of my datagrid because of alignment of both.
> NOTE: I must have (and want) the datagrid width variable and not fixed
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>

Set html table width at run time (in code)

Hi

How can I get a html control in my code?
I have a html table that I want the width is defined in code at run time,
i.e., I have this table and I have a datagrid. This datagrid have a variable
width because the number of columns depends of something that I have (that
is not important for this). Now, what I want is that the html table have
always the same width of my datagrid because of alignment of both.

NOTE: I must have (and want) the datagrid width variable and not fixed

--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
rucaset its attribute runat=server, but you'll probably still have problems
while tables align width depending on its content... You can hardly create
different tables with same width. The only chance is when content never
exceedes desired table (or better said cell) width.

--
RobertK
{ Clever? No just smart. }

"ruca" <ruuca@.iol.pt> wrote in message
news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> Hi
> How can I get a html control in my code?
> I have a html table that I want the width is defined in code at run time,
> i.e., I have this table and I have a datagrid. This datagrid have a
variable
> width because the number of columns depends of something that I have (that
> is not important for this). Now, what I want is that the html table have
> always the same width of my datagrid because of alignment of both.
> NOTE: I must have (and want) the datagrid width variable and not fixed
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
Thanks
Now, how can I get the widht value at run time of a datagrid?

I have this:
Dim dgPx As Unit
dgPx = myDataGrid.Width()

But dgPx.Value does not have the value of the grid after binding grid.
Can you help?

--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

"Robert Koritnik" <robert.koritnik.removethis@.avtenta.si> escreveu na
mensagem news:%23hnurAxbEHA.2816@.TK2MSFTNGP11.phx.gbl...
> set its attribute runat=server, but you'll probably still have problems
> while tables align width depending on its content... You can hardly create
> different tables with same width. The only chance is when content never
> exceedes desired table (or better said cell) width.
> --
> RobertK
> { Clever? No just smart. }
> "ruca" <ruuca@.iol.pt> wrote in message
> news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> > Hi
> > How can I get a html control in my code?
> > I have a html table that I want the width is defined in code at run
time,
> > i.e., I have this table and I have a datagrid. This datagrid have a
> variable
> > width because the number of columns depends of something that I have
(that
> > is not important for this). Now, what I want is that the html table have
> > always the same width of my datagrid because of alignment of both.
> > NOTE: I must have (and want) the datagrid width variable and not fixed
> > --
> > Programming ASP.NET with VB.NET
> > Thank's (if you try to help me)
> > Hope this help you (if I try to help you)
> > ruca
You will have to set that. I told you in my first answer this is a tough
one. The best suggestion I could give you is to put both (table and
Datagrid) inside another table set both control's width to 100%. They would
perfectly align and everything will depend on the width of the containing
table cell.

And you probably won't have to wory about widths of both parts of the
page... Or better said tables, while a datagris is also a table.

--
RobertK
{ Clever? No just smart. }

"ruca" <ruuca@.iol.pt> wrote in message
news:ekMCZTxbEHA.1048@.tk2msftngp13.phx.gbl...
> Thanks
> Now, how can I get the widht value at run time of a datagrid?
> I have this:
> Dim dgPx As Unit
> dgPx = myDataGrid.Width()
> But dgPx.Value does not have the value of the grid after binding grid.
> Can you help?
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
> "Robert Koritnik" <robert.koritnik.removethis@.avtenta.si> escreveu na
> mensagem news:%23hnurAxbEHA.2816@.TK2MSFTNGP11.phx.gbl...
> > set its attribute runat=server, but you'll probably still have problems
> > while tables align width depending on its content... You can hardly
create
> > different tables with same width. The only chance is when content never
> > exceedes desired table (or better said cell) width.
> > --
> > RobertK
> > { Clever? No just smart. }
> > "ruca" <ruuca@.iol.pt> wrote in message
> > news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> > > Hi
> > > > How can I get a html control in my code?
> > > I have a html table that I want the width is defined in code at run
> time,
> > > i.e., I have this table and I have a datagrid. This datagrid have a
> > variable
> > > width because the number of columns depends of something that I have
> (that
> > > is not important for this). Now, what I want is that the html table
have
> > > always the same width of my datagrid because of alignment of both.
> > > > NOTE: I must have (and want) the datagrid width variable and not fixed
> > > > > --
> > > Programming ASP.NET with VB.NET
> > > Thank's (if you try to help me)
> > > Hope this help you (if I try to help you)
> > > ruca
> >
One doesn't do this sort of things in the code. Put both the table and the
grid in another table as it's been suggested in another reply.

Eliyahu

"ruca" <ruuca@.iol.pt> wrote in message
news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> Hi
> How can I get a html control in my code?
> I have a html table that I want the width is defined in code at run time,
> i.e., I have this table and I have a datagrid. This datagrid have a
variable
> width because the number of columns depends of something that I have (that
> is not important for this). Now, what I want is that the html table have
> always the same width of my datagrid because of alignment of both.
> NOTE: I must have (and want) the datagrid width variable and not fixed
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca

Set MaxLength on form Load

Hi,

Does anyone know how to populate the maxlength property of an asp:textbox on page load?

I'm getting the value from the my config table in my DB

When I try setting myControl.MaxLength=10 in the onload event
It's not written to the control and when I enter text I'm not restricted at all

I've also tried

<asp:textbox id="Abstract" Runat="server" Wrap="True" Rows="11" Columns="45" TextMode="MultiLine" maxlength="<%=SummaryLimit%>"></asp:textbox>

' And

<asp:textbox id="Abstract" Runat="server" Wrap="True" Rows="11" Columns="45" TextMode="MultiLine" maxlength="<%=Convert.ToInt32(SummaryLimit)%>"></asp:textbox>
Geting error - <%=SummaryLimit%> is not a valid value for Int32.
And
<%=Convert.ToInt32(SummaryLimit)%> is not a valid value for Int32.

SummaryLimit Value is declared and assigned as an Int32
Dim m_iSummaryLimit As Int32 = 250

Public Property SummaryLimit() As Int32
Get
Return Convert.ToInt32(m_iSummaryLimit)
End Get
Set(ByVal Value As Int32)
m_iSummaryLimit = Convert.ToInt32(Value)
End Set
End PropertyThe textbox control when in multiline mode actually renders as a HTML textarea therefore on a textarea there is no maxlength property so maxlength does not work. One of the ways to control this is to use javascript instead.
Basilisk,

Thanks for that, just wasted the whole morning trying to get it working.

Cheers Al
I did want to pipe in and say that when you use the following:

<%= ... %>

in an item tag, you need to surround it with single quotes - ' - and not double quotes - " -.
Lord Rat,

Thanks, feel free to pop out of your cave with useful tips like that at anytime :D

Cheers Al

Tuesday, March 13, 2012

Set object properties via a loop?

I have a data container object that holds user info, with one public property mapping to each field in my database table.

When retrieving a user's info from my db I'm using a DataReader, and writing code like this:

myDBObj.name = reader["name"];
myDBObj.id = reader["id"];

Etc, etc. This works ok, but I was hoping to use the DataReader's GetName and FieldCount methods to automate setting my property values.

Something like:

for (int i = 0; i <= reader.FieldCount; i++)
{
string fieldName = reader.GetName(i);
usr.[fieldName] = (reader.GetDataTypeName(i))reader[i];
}

The part in bold is throwing me--is there a way to use a variable in determining which property I'm assigning? Is there another way to do what I'm trying?

Thanks!

Aaron

You could try reader[i].ToString()

usr.[fieldName] = reader[i].ToString();

Sample Code:

SqlConnection connection = new SqlConnection(ConnectionString);
SqlCommand commond = new SqlCommand("SELECT * FROM TEST");
DataSet fillDataSet = new DataSet();
commond.Connection = connection;
commond.CommandType = CommandType.Text;
connection.Open();
SqlDataReader dr;
dr = commond.ExecuteReader();
while(dr.Read())
{
for(int i=0; i<dr.FieldCount;i++)
{
Response.Write(dr.GetName(i) + ":"+ i.ToString() +":" + dr[i].ToString());
Response.Write("<br>");
}
}
connection.Close();


Obtaining the info via the datareader isn't the problem, the issue is that the object I'm creating (objUserDetail) has properties of varying types (strings, ints, datetimes, etc).

While I could certainly simply write out a long list of property assignments and cast the datareader's info in the correct type each time, I'd much rather figure out a way to do it via a loop.

I figured out how to use a PropertyInfo object to get the names of the properties dynamically at runtime, but now the problem is the datareader is sending all the data back as a string, and I can't find a way to convert/cast it into the format the various properties are expecting.

Normally I would do this:

objUserDetail.UserID = (int)reader["UserID"];

But I need a way to convert the reader's field value dynamically.

Anyone know how?


Can you try this..

(dr[i].GetType()) dr[i].ToString()

while(dr.Read())
{
for(int i=0; i<dr.FieldCount;i++)
{
Response.Write(dr.GetName(i) + ":"+ dr[i].GetType() +":" + dr[i].ToString());
Response.Write("<br>");
}
}

Why don't you use TypeDataSet?


like this:

Dim myDBobjAs New usrDim fieldNameAs String Dim flagsAs BindingFlags = BindingFlags.InstanceOr BindingFlags.Public Or BindingFlags.IgnoreCaseOr BindingFlags.Static Or BindingFlags.FlattenHierarchyDim pAs PropertyInfoDim readerAs System.Data.SqlClient.SqlDataReader = GetTheReader()'populate one entityFor iAs Integer = 0To (reader.FieldCount - 1) fieldname = reader.GetName(i) p =GetType(usr).GetProperty(fieldName, flags) p.SetValue(myDBobj, reader(i),Nothing)Next

Thanks for your help, everyone!

I was able to get it working, and now I'm reconsidering the whole data table class concept, since that's what DataSets are for, right?

aaron


DataSets are basically just collections of DataTables.

NC...

Set parameter value

I add a datasource to a page and configure it do insert and update to database table. I can see the select, insert and update commands and correspond parameters in the source file.

Now I need pass the values to the parameters. Most parameters value use form parameters. But there is one parameter value do not exist on the page and need to be set. But HOW?

The following seems the only code I can do which is "ADD" a parameter which already exists.

SqlDataSource1.InsertParameters.Add("UserId", userid)

Is there a simple way just set the value of the parameter?

SqlDataSource1.InsertParameters("UserId").value= userid 'DOES'T WORK

Ying

Is this VB? if it is C# then you could do this:

SqlDataSource1.InsertParameters["UserId"].value= userid;


actually, I meant:

SqlDataSource1.InsertParameters["UserId"].DefaultValue = userid