473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing parameter from textbox

Hello,

Please forgive my simple question, but i don't know the correct synatx.

From the masterpage i want to put a text in an textbox and then select an
item in the datagrid. I do know how to pass the items in the datagrid(e.g.
PLU, description, etc.) to an other (detail)page, but i don't know the
correct syntax of how to pass the textbox value to the detailpage.

I have the following code:

<asp:DataGrid id="dgrArticle " runat="server" autoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<a href='ArticleDe tail.aspx?debto rid=<%#textbox1 .text%>&
plu=<%#DataBind er.Eval(Contain er.DataItem,
"PLU")%>&

description=<%# DataBinder.Eval (Container.Data Item,"DESCRIPTI ON")%
</a>
</ItemTemplate>
</asp:TemplateCol umn
</Columns>
</asp:DataGrid>

The result is now:
http://localhost:8081/ArticleDetail....iption=SOME_DE
SCRIPTION

But must be (if textbox1.text=" 12345") :
http://localhost:8081/ArticleDetail....description=SO
ME_DESCRIPTION

Thanx, Cemal
Nov 18 '05 #1
7 3433
I don't know if I understand what you're asking, but, you are trying to
include the value of textbox1.text in a client side control, right? Why
don't you try to use a server side control, and redirect the page in the
OnClick event.

<asp:linkbutt on id=LinkButton1 onclick='<%#
NavToURL(DataBi nder.Eval(Conta iner.DataItem, "PLU"),
DataBinder.Eval (Container.Data Item, "Description")) %>'
runat="server"> LinkButton</asp:linkbutton>

Protected Sub NavToURL(ByVal PLU As String, ByVal Description As String)
Dim URL As String = "ArticleDetail. aspx?debtroid=" _
& Server.UrlEncod e(Me.TextBox1.T ext) _
& "&plu=" & Server.UrlEncod e(PLU) & "&descripti on=" &
Server.UrlEncod e(Description)
Response.Redire ct(URL)
End Sub

"Cemal Karademir" <c.*********@zo nnet.nl> wrote in message
news:e5******** ******@TK2MSFTN GP11.phx.gbl...
Hello,

Please forgive my simple question, but i don't know the correct synatx.

From the masterpage i want to put a text in an textbox and then select an
item in the datagrid. I do know how to pass the items in the datagrid(e.g.
PLU, description, etc.) to an other (detail)page, but i don't know the
correct syntax of how to pass the textbox value to the detailpage.

I have the following code:

<asp:DataGrid id="dgrArticle " runat="server" autoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<a href='ArticleDe tail.aspx?debto rid=<%#textbox1 .text%>&
plu=<%#DataBind er.Eval(Contain er.DataItem,
"PLU")%>&

description=<%# DataBinder.Eval (Container.Data Item,"DESCRIPTI ON")%
</a>
</ItemTemplate>
</asp:TemplateCol umn
</Columns>
</asp:DataGrid>

The result is now:
http://localhost:8081/ArticleDetail....iption=SOME_DE
SCRIPTION

But must be (if textbox1.text=" 12345") :
http://localhost:8081/ArticleDetail....description=SO
ME_DESCRIPTION

Thanx, Cemal

Nov 18 '05 #2
I think this is what i'm looking for, but how dows this work in an datagrid
(see examples below). I forgot to say that I don't have much experience with
ASP.NET.

By the way, what are client and server side controls and what are the
differences/when do I use them?

Thanx, Cemal

"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
I don't know if I understand what you're asking, but, you are trying to
include the value of textbox1.text in a client side control, right? Why
don't you try to use a server side control, and redirect the page in the
OnClick event.

<asp:linkbutt on id=LinkButton1 onclick='<%#
NavToURL(DataBi nder.Eval(Conta iner.DataItem, "PLU"),
DataBinder.Eval (Container.Data Item, "Description")) %>'
runat="server"> LinkButton</asp:linkbutton>

Protected Sub NavToURL(ByVal PLU As String, ByVal Description As String)
Dim URL As String = "ArticleDetail. aspx?debtroid=" _
& Server.UrlEncod e(Me.TextBox1.T ext) _
& "&plu=" & Server.UrlEncod e(PLU) & "&descripti on=" &
Server.UrlEncod e(Description)
Response.Redire ct(URL)
End Sub

"Cemal Karademir" <c.*********@zo nnet.nl> wrote in message
news:e5******** ******@TK2MSFTN GP11.phx.gbl...
Hello,

Please forgive my simple question, but i don't know the correct synatx.

From the masterpage i want to put a text in an textbox and then select an item in the datagrid. I do know how to pass the items in the datagrid(e.g. PLU, description, etc.) to an other (detail)page, but i don't know the
correct syntax of how to pass the textbox value to the detailpage.

I have the following code:

<asp:DataGrid id="dgrArticle " runat="server" autoGenerateCol umns="False"> <Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<a href='ArticleDe tail.aspx?debto rid=<%#textbox1 .text%>&
plu=<%#DataBind er.Eval(Contain er.DataItem,
"PLU")%>&

description=<%# DataBinder.Eval (Container.Data Item,"DESCRIPTI ON")%
</a>
</ItemTemplate>
</asp:TemplateCol umn
</Columns>
</asp:DataGrid>

The result is now:
http://localhost:8081/ArticleDetail....iption=SOME_DE SCRIPTION

But must be (if textbox1.text=" 12345") :
http://localhost:8081/ArticleDetail....description=SO ME_DESCRIPTION

Thanx, Cemal


Nov 18 '05 #3
Cemal,
First, what I mean by server side and client side controls is, a server
side control is one that posts to the server and a client control doesn't.
This may not be the correct definition, it's just what I am referring to.
That is why the <a href= will not work. The value of <a href> must be either
set when the page loads or through some scripting method. While I know the
..Net server controls do just that, I don't know how to duplicate this
behavior manually. Any of the controls listed on the WebForms toolbox band
should be server side controls.

In your datagrid control I am working under the assumption that it will have
a total of two columns, the first is PLU and the second is the description.
The PLU column will host the control that posts/redirects to the details
page. It looks like you are already using template columns, which need to
remain, at least for the PLU column. The Description column does not have to
be templated. Start by editing the template for the PLU column, Under the
ItemTemplate section drop in a LinkButton control. Set its id to "lnkPLU"
and end template editing. If your description column is templated remove it
and simply add a bound column in its place. Set the Data Field to the name
of the field that houses the data for the description column; in your
example below it looks like it should be set to DESCRIPTION. Now, in the
datagrid's ItemCommand event, write the following code, you should supply
your own error handling.

Private Sub DataGrid1_ItemC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DataGrid1.ItemC ommand
Try
Dim Item As DataGridItem = CType(e.Item, DataGridItem)
Dim URL As String
With Item
URL = "ArticleDetail. aspx?debtroid=" _
& Server.UrlEncod e(Me.TextBox1.T ext.Trim) _
& "&plu=" &
Server.UrlEncod e(CType(.Cells( 0).FindControl( "lnkPLU"), LinkButton).Tex t) &
"&descripti on=" & Server.UrlEncod e(.Cells(1).Tex t)
End With
Response.Redire ct(URL)
Catch ex as Exception
'Some error handling code
End Try
End Sub

I'm sure there are better ways of doing this, however, I don't know any. Pay
attention to the type conversion, a template column will hold controls,
that's why we have to do a little casting to get the value, on the other
hand, we can directly get the value of a bound column using the
cells(CellIndex ).Text property.

Hope this helps,
Jared

"Cemal Karademir" <c.*********@zo nnet.nl> wrote in message
news:Oi******** ******@TK2MSFTN GP11.phx.gbl...
I think this is what i'm looking for, but how dows this work in an datagrid
(see examples below). I forgot to say that I don't have much experience
with
ASP.NET.

By the way, what are client and server side controls and what are the
differences/when do I use them?

Thanx, Cemal

"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
I don't know if I understand what you're asking, but, you are trying to
include the value of textbox1.text in a client side control, right? Why
don't you try to use a server side control, and redirect the page in the
OnClick event.

<asp:linkbutt on id=LinkButton1 onclick='<%#
NavToURL(DataBi nder.Eval(Conta iner.DataItem, "PLU"),
DataBinder.Eval (Container.Data Item, "Description")) %>'
runat="server"> LinkButton</asp:linkbutton>

Protected Sub NavToURL(ByVal PLU As String, ByVal Description As String)
Dim URL As String = "ArticleDetail. aspx?debtroid=" _
& Server.UrlEncod e(Me.TextBox1.T ext) _
& "&plu=" & Server.UrlEncod e(PLU) & "&descripti on=" &
Server.UrlEncod e(Description)
Response.Redire ct(URL)
End Sub

"Cemal Karademir" <c.*********@zo nnet.nl> wrote in message
news:e5******** ******@TK2MSFTN GP11.phx.gbl...
> Hello,
>
> Please forgive my simple question, but i don't know the correct synatx.
>
> From the masterpage i want to put a text in an textbox and then select an > item in the datagrid. I do know how to pass the items in the datagrid(e.g. > PLU, description, etc.) to an other (detail)page, but i don't know the
> correct syntax of how to pass the textbox value to the detailpage.
>
> I have the following code:
>
> <asp:DataGrid id="dgrArticle " runat="server" autoGenerateCol umns="False"> > <Columns>
> <asp:TemplateCo lumn>
> <ItemTemplate >
> <a href='ArticleDe tail.aspx?debto rid=<%#textbox1 .text%>&
> plu=<%#DataBind er.Eval(Contain er.DataItem,
> "PLU")%>&
>
> description=<%# DataBinder.Eval (Container.Data Item,"DESCRIPTI ON")%
> </a>
> </ItemTemplate>
> </asp:TemplateCol umn
> </Columns>
> </asp:DataGrid>
>
> The result is now:
> http://localhost:8081/ArticleDetail....iption=SOME_DE > SCRIPTION
>
> But must be (if textbox1.text=" 12345") :
> http://localhost:8081/ArticleDetail....description=SO > ME_DESCRIPTION
>
> Thanx, Cemal
>
>



Nov 18 '05 #4
Okay, I did evrything you said, but now i get an error message:
System.Argument OutOfRangeExcep tion: .......

Am i doimg something wrong? I include below the complete source for further
investigations. Please help we this?

Thanx, Cemal

<%@ Page Language="VB" Debug="TRUE" %>
<%@ import Namespace="Syst em.Data.OleDb" %>
<script runat="server">

Sub Page_Load
dim SQLString as string="Select * from ARTICLE"
dim Conn as OleDbConnection
dim ConnectionStrin g as string="Provide r=Microsoft.Jet .OLEDB.4.0;
Ole DB Services=-4; Data Source=C:\Smart Soft.NET\ORSDB. mdb"
dim Cmdselect as OleDbCommand
dim dtrArticle as OleDbDataReader

Conn = New OleDbConnection (ConnectionStri ng)
Conn.Open()
CmdSelect = New OleDbCommand(SQ LString, Conn)
dtrArticle = CmdSelect.Execu teReader()

While dtrArticle.Read ()
dgrArticle.Data Source=dtrArtic le
dgrArticle.Data Bind()
End While

dtrArticle.Clos e()
Conn.Close()
End Sub

Private Sub ItemCommand(ByV al source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
Dim Item As DataGridItem = CType(e.Item, DataGridItem)
Dim URL As String

With Item
URL = "ArticleDetail. aspx?debtorid=" & (Me.txtDebtor.T ext.Trim)
& _
"&plu=" &
Server.UrlEncod e(CType(.Cells( 0).FindControl( "lnkPLU"), LinkButton).Tex t) &
_
"&descripti on=" & Server.UrlEncod e(.Cells(1).Tex t)
End With

Response.Redire ct(URL)
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="txtDebtor" runat="server"
Width="100px"></asp:TextBox>
<br />
<asp:DataGrid id="dgrArticle " runat="server"
OnItemCommand=" ItemCommand" autoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on id="lnkPLU" runat="server">
<%#DataBinder.E val(Container.D ataItem,
"PLU")%>
</asp:LinkButton>
<%#DataBinder.E val(Container.D ataItem,
"DESCRIPTION")% >
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
</p>
</form>
</body>
</html>
Nov 18 '05 #5
Cemal,
You are close, but it looks like both you and I missed a step. The first
thing to fix is you need to add a second column, a databound column; this
column will be used for the description. The below definition should work;
this is why you were receiving the System.Argument OutOfRangeExcep tion, there
was only one column. Now, I forgot to tell you to bind the "Text" property
of the linkbutton to the PLU field from the datasource. You can do it a
couple of ways. If you are editing the template column you can select
lnkPLU, open the (DataBindings) editor, select "Text", choose custom binding
expression, and set the value to DataBinder.Eval (Container.Data Item, "PLU").
Alternatively, set the "Text" property of the linkbutton control as shown
below, both produce the same results, or replace your current datagrid's
definition with the one below.

<asp:DataGrid id="dgrArticle " runat="server" OnItemCommand=" ItemCommand"
autoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn HeaderText="PLU ">
<ItemTemplate >
<asp:LinkButt on id="lnkPLU" runat="server"
Text='<%#DataBi nder.Eval(Conta iner.DataItem, "PLU")%>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:BoundColum n DataField="DESC RIPTION"
HeaderText="Des cription"></asp:BoundColumn >
</Columns>
</asp:DataGrid>

On a side note, you may have faster load times if you don't populate the
data on postbacks, unless there is a chance the data will change between the
posts and it will make a difference in the results.

Remember, the page load event will fire before the ItemCommand event so
when you click an item you are always rereading from the database and
filling the datagrid each time. In this case you probably don't need to do
this.

Try something like this in the page load event:

If Not IsPostBack Then
Dim Conn As New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Ole DB
Services=-4; Data Source=C:\Smart Soft.NET\ORSDB. mdb")
Conn.Open()
If Conn.State = ConnectionState .Open Then
Try
Dim Cmdselect As New OleDbCommand("S ELECT * FROM ARTICLE", Conn)
dgrArticle.Data Source = Cmdselect.Execu teReader
dgrArticle.Data Bind()
Catch ex As Exception
'Error handling here
Finally
Conn.Close()
End Try
End If
End If

Jared

"Cemal Karademir" <c.*********@zo nnet.nl> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
Okay, I did evrything you said, but now i get an error message:
System.Argument OutOfRangeExcep tion: .......

Am i doimg something wrong? I include below the complete source for
further
investigations. Please help we this?

Thanx, Cemal

<%@ Page Language="VB" Debug="TRUE" %>
<%@ import Namespace="Syst em.Data.OleDb" %>
<script runat="server">

Sub Page_Load
dim SQLString as string="Select * from ARTICLE"
dim Conn as OleDbConnection
dim ConnectionStrin g as string="Provide r=Microsoft.Jet .OLEDB.4.0;
Ole DB Services=-4; Data Source=C:\Smart Soft.NET\ORSDB. mdb"
dim Cmdselect as OleDbCommand
dim dtrArticle as OleDbDataReader

Conn = New OleDbConnection (ConnectionStri ng)
Conn.Open()
CmdSelect = New OleDbCommand(SQ LString, Conn)
dtrArticle = CmdSelect.Execu teReader()

While dtrArticle.Read ()
dgrArticle.Data Source=dtrArtic le
dgrArticle.Data Bind()
End While

dtrArticle.Clos e()
Conn.Close()
End Sub

Private Sub ItemCommand(ByV al source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
Dim Item As DataGridItem = CType(e.Item, DataGridItem)
Dim URL As String

With Item
URL = "ArticleDetail. aspx?debtorid=" & (Me.txtDebtor.T ext.Trim)
& _
"&plu=" &
Server.UrlEncod e(CType(.Cells( 0).FindControl( "lnkPLU"), LinkButton).Tex t)
&
_
"&descripti on=" & Server.UrlEncod e(.Cells(1).Tex t)
End With

Response.Redire ct(URL)
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="txtDebtor" runat="server"
Width="100px"></asp:TextBox>
<br />
<asp:DataGrid id="dgrArticle " runat="server"
OnItemCommand=" ItemCommand" autoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on id="lnkPLU" runat="server">
<%#DataBinder.E val(Container.D ataItem,
"PLU")%>
</asp:LinkButton>
<%#DataBinder.E val(Container.D ataItem,
"DESCRIPTION")% >
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
</p>
</form>
</body>
</html>

Nov 18 '05 #6
Jared,
Thank you very much for your help, it works just like i wanted.
I will now analyse the code what it does, so that i understand what is
happening.
Thanx, Cemal.

"Jared" <VB***********@ email.com> schreef in bericht
news:10******** *****@corp.supe rnews.com...
Cemal,
You are close, but it looks like both you and I missed a step. The first thing to fix is you need to add a second column, a databound column; this
column will be used for the description. The below definition should work;
this is why you were receiving the System.Argument OutOfRangeExcep tion, there was only one column. Now, I forgot to tell you to bind the "Text" property
of the linkbutton to the PLU field from the datasource. You can do it a
couple of ways. If you are editing the template column you can select
lnkPLU, open the (DataBindings) editor, select "Text", choose custom binding expression, and set the value to DataBinder.Eval (Container.Data Item, "PLU"). Alternatively, set the "Text" property of the linkbutton control as shown
below, both produce the same results, or replace your current datagrid's
definition with the one below.

<asp:DataGrid id="dgrArticle " runat="server" OnItemCommand=" ItemCommand"
autoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn HeaderText="PLU ">
<ItemTemplate >
<asp:LinkButt on id="lnkPLU" runat="server"
Text='<%#DataBi nder.Eval(Conta iner.DataItem, "PLU")%>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:BoundColum n DataField="DESC RIPTION"
HeaderText="Des cription"></asp:BoundColumn >
</Columns>
</asp:DataGrid>

On a side note, you may have faster load times if you don't populate the
data on postbacks, unless there is a chance the data will change between the posts and it will make a difference in the results.

Remember, the page load event will fire before the ItemCommand event so
when you click an item you are always rereading from the database and
filling the datagrid each time. In this case you probably don't need to do
this.

Try something like this in the page load event:

If Not IsPostBack Then
Dim Conn As New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Ole DB Services=-4; Data Source=C:\Smart Soft.NET\ORSDB. mdb")
Conn.Open()
If Conn.State = ConnectionState .Open Then
Try
Dim Cmdselect As New OleDbCommand("S ELECT * FROM ARTICLE", Conn) dgrArticle.Data Source = Cmdselect.Execu teReader
dgrArticle.Data Bind()
Catch ex As Exception
'Error handling here
Finally
Conn.Close()
End Try
End If
End If

Jared

"Cemal Karademir" <c.*********@zo nnet.nl> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
Okay, I did evrything you said, but now i get an error message:
System.Argument OutOfRangeExcep tion: .......

Am i doimg something wrong? I include below the complete source for
further
investigations. Please help we this?

Thanx, Cemal

<%@ Page Language="VB" Debug="TRUE" %>
<%@ import Namespace="Syst em.Data.OleDb" %>
<script runat="server">

Sub Page_Load
dim SQLString as string="Select * from ARTICLE"
dim Conn as OleDbConnection
dim ConnectionStrin g as string="Provide r=Microsoft.Jet .OLEDB.4.0;
Ole DB Services=-4; Data Source=C:\Smart Soft.NET\ORSDB. mdb"
dim Cmdselect as OleDbCommand
dim dtrArticle as OleDbDataReader

Conn = New OleDbConnection (ConnectionStri ng)
Conn.Open()
CmdSelect = New OleDbCommand(SQ LString, Conn)
dtrArticle = CmdSelect.Execu teReader()

While dtrArticle.Read ()
dgrArticle.Data Source=dtrArtic le
dgrArticle.Data Bind()
End While

dtrArticle.Clos e()
Conn.Close()
End Sub

Private Sub ItemCommand(ByV al source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
Dim Item As DataGridItem = CType(e.Item, DataGridItem)
Dim URL As String

With Item
URL = "ArticleDetail. aspx?debtorid=" & (Me.txtDebtor.T ext.Trim) & _
"&plu=" &
Server.UrlEncod e(CType(.Cells( 0).FindControl( "lnkPLU"), LinkButton).Tex t) &
_
"&descripti on=" & Server.UrlEncod e(.Cells(1).Tex t)
End With

Response.Redire ct(URL)
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="txtDebtor" runat="server"
Width="100px"></asp:TextBox>
<br />
<asp:DataGrid id="dgrArticle " runat="server"
OnItemCommand=" ItemCommand" autoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on id="lnkPLU" runat="server">
<%#DataBinder.E val(Container.D ataItem,
"PLU")%>
</asp:LinkButton>
<%#DataBinder.E val(Container.D ataItem,
"DESCRIPTION")% >
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
</p>
</form>
</body>
</html>


Nov 18 '05 #7
Your welcome Cemal, if you don't understand what is going on let me know and
I will try to explain.
Jared

"Cemal Karademir" <c.*********@zo nnet.nl> wrote in message
news:OB******** ******@TK2MSFTN GP11.phx.gbl...
Jared,
Thank you very much for your help, it works just like i wanted.
I will now analyse the code what it does, so that i understand what is
happening.
Thanx, Cemal.

"Jared" <VB***********@ email.com> schreef in bericht
news:10******** *****@corp.supe rnews.com...
Cemal,
You are close, but it looks like both you and I missed a step. The

first
thing to fix is you need to add a second column, a databound column; this
column will be used for the description. The below definition should
work;
this is why you were receiving the System.Argument OutOfRangeExcep tion,

there
was only one column. Now, I forgot to tell you to bind the "Text"
property
of the linkbutton to the PLU field from the datasource. You can do it a
couple of ways. If you are editing the template column you can select
lnkPLU, open the (DataBindings) editor, select "Text", choose custom

binding
expression, and set the value to DataBinder.Eval (Container.Data Item,

"PLU").
Alternatively, set the "Text" property of the linkbutton control as shown
below, both produce the same results, or replace your current datagrid's
definition with the one below.

<asp:DataGrid id="dgrArticle " runat="server" OnItemCommand=" ItemCommand"
autoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn HeaderText="PLU ">
<ItemTemplate >
<asp:LinkButt on id="lnkPLU" runat="server"
Text='<%#DataBi nder.Eval(Conta iner.DataItem, "PLU")%>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:BoundColum n DataField="DESC RIPTION"
HeaderText="Des cription"></asp:BoundColumn >
</Columns>
</asp:DataGrid>

On a side note, you may have faster load times if you don't populate the
data on postbacks, unless there is a chance the data will change between

the
posts and it will make a difference in the results.

Remember, the page load event will fire before the ItemCommand event so
when you click an item you are always rereading from the database and
filling the datagrid each time. In this case you probably don't need to
do
this.

Try something like this in the page load event:

If Not IsPostBack Then
Dim Conn As New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Ole

DB
Services=-4; Data Source=C:\Smart Soft.NET\ORSDB. mdb")
Conn.Open()
If Conn.State = ConnectionState .Open Then
Try
Dim Cmdselect As New OleDbCommand("S ELECT * FROM ARTICLE",

Conn)
dgrArticle.Data Source = Cmdselect.Execu teReader
dgrArticle.Data Bind()
Catch ex As Exception
'Error handling here
Finally
Conn.Close()
End Try
End If
End If

Jared

"Cemal Karademir" <c.*********@zo nnet.nl> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
> Okay, I did evrything you said, but now i get an error message:
> System.Argument OutOfRangeExcep tion: .......
>
> Am i doimg something wrong? I include below the complete source for
> further
> investigations. Please help we this?
>
> Thanx, Cemal
>
> <%@ Page Language="VB" Debug="TRUE" %>
> <%@ import Namespace="Syst em.Data.OleDb" %>
> <script runat="server">
>
> Sub Page_Load
> dim SQLString as string="Select * from ARTICLE"
> dim Conn as OleDbConnection
> dim ConnectionStrin g as
> string="Provide r=Microsoft.Jet .OLEDB.4.0;
> Ole DB Services=-4; Data Source=C:\Smart Soft.NET\ORSDB. mdb"
> dim Cmdselect as OleDbCommand
> dim dtrArticle as OleDbDataReader
>
> Conn = New OleDbConnection (ConnectionStri ng)
> Conn.Open()
> CmdSelect = New OleDbCommand(SQ LString, Conn)
> dtrArticle = CmdSelect.Execu teReader()
>
> While dtrArticle.Read ()
> dgrArticle.Data Source=dtrArtic le
> dgrArticle.Data Bind()
> End While
>
> dtrArticle.Clos e()
> Conn.Close()
> End Sub
>
> Private Sub ItemCommand(ByV al source As Object, ByVal e As
> System.Web.UI.W ebControls.Data GridCommandEven tArgs)
> Dim Item As DataGridItem = CType(e.Item, DataGridItem)
> Dim URL As String
>
> With Item
> URL = "ArticleDetail. aspx?debtorid=" & (Me.txtDebtor.T ext.Trim) > & _
> "&plu=" &
> Server.UrlEncod e(CType(.Cells( 0).FindControl( "lnkPLU"), LinkButton).Tex t) > &
> _
> "&descripti on=" & Server.UrlEncod e(.Cells(1).Tex t)
> End With
>
> Response.Redire ct(URL)
> End Sub
>
> </script>
> <html>
> <head>
> </head>
> <body>
> <form runat="server">
> <p>
> <asp:TextBox id="txtDebtor" runat="server"
> Width="100px"></asp:TextBox>
> <br />
> <asp:DataGrid id="dgrArticle " runat="server"
> OnItemCommand=" ItemCommand" autoGenerateCol umns="False">
> <Columns>
> <asp:TemplateCo lumn>
> <ItemTemplate >
> <asp:LinkButt on id="lnkPLU" runat="server">
> <%#DataBinder.E val(Container.D ataItem,
> "PLU")%>
> </asp:LinkButton>
> <%#DataBinder.E val(Container.D ataItem,
> "DESCRIPTION")% >
> </ItemTemplate>
> </asp:TemplateCol umn>
> </Columns>
> </asp:DataGrid>
> </p>
> </form>
> </body>
> </html>
>
>



Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1445
by: AlexB | last post by:
I have a sub routine that performs an operation on all of the controls on an ASP.NET page using the If TypeOf..Is X statement. I want to pass the class, X, in as a parameter. Is this possible? Sub(byval x as ???) For i = 0 to Controls.count -1 If Typeof controls(i) Is X then 'Do something End if
39
7597
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down indicate: a) That I don't know enough b) Passing arguments by ref is bad
1
3617
by: Maria | last post by:
Hello! I am new to Crystal reports an I have problems passing parameters form outside to Crystal report an creating a report with data from more than one table This is the problem: I have to make a report( VS.NET, C#, Web Form) with 3 parts and with data from three tables: 1st part: all the field values form table1 coresponding to an...
1
1186
by: freddy | last post by:
ok lets say I use the insertcommand in ado.net to insert a string from the info the user rights in a textbox. The textbox name is txtName.text do I use ('" +txtname.text +"'); or do I use a parameter and if so how would I change ('" +txtname.text +"'); to a parameter Thanks
13
8195
by: anonymike | last post by:
Hello, I started working with the ObjectDataSource today. I have the select, and have been working on getting the update method to work. Here is the asp code for my Data source: <asp:ObjectDataSource ID="dsourceApps" runat="server" SelectMethod="getAllApplications" TypeName="AppMgr.AppManager" UpdateMethod="updateAppHdr"...
4
2748
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx to a stored procedure on the details2.aspx page. I can successfully pass the values from the listbox control to a
0
987
by: Phillip Vong | last post by:
Doing this in VS2005. ASPX in VB code. This image details my problem. http://ebay.philvong.com/help.jpg I have a simple FormView1 bound to a SQLDataSource1. In edit mode, Label1 is bound to a value. Under this, I added another textbox (ID=TEXTBOX1) and another SQLDataSource2. Then I added a details view (ID=DetailView1). Textbox1 is...
2
4279
by: Geoff | last post by:
Consider the procedure Private Sub Adder(ByVal Num1 As Integer, etc. ) End Sub
5
1498
by: teqkillah | last post by:
Good Day Guys! I have a new problem with my program. i've already created my report in crystal. within my report it has parameter (myinvoice) that the user needs to input. after that ive attached that report tom my reportviewer. i also added a textbox in my form where my value for the parameter is assigned. the problem now is the data being...
1
5802
by: imtmub | last post by:
Hi All, I have mainpage (POselect.aspx). language VB In that page i have a textbox (txtPOId) and command button(Button1) When i press then button its should send the textbox value to Crystal report and open parameter. I have crystal report (CrystalReport1) that display the matched records what client entered in the textbox from main page. ...
0
7457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7410
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5320
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4941
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.