Re: Passing parameter from textbox
From: Jared (VB_Puzzled_VB_at_email.com)
Date: 07/24/04
- Next message: Jared: "Re: Reading a http page"
- Previous message: JIM.H.: "number of row returned"
- In reply to: Cemal Karademir: "Re: Passing parameter from textbox"
- Next in thread: Cemal Karademir: "Re: Passing parameter from textbox"
- Reply: Cemal Karademir: "Re: Passing parameter from textbox"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 24 Jul 2004 08:31:08 -0500
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.ArgumentOutOfRangeException, 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.DataItem, "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"
autoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="PLU">
<ItemTemplate>
<asp:LinkButton id="lnkPLU" runat="server"
Text='<%#DataBinder.Eval(Container.DataItem, "PLU")%>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="DESCRIPTION"
HeaderText="Description"></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=Microsoft.Jet.OLEDB.4.0;Ole DB
Services=-4; Data Source=C:\SmartSoft.NET\ORSDB.mdb")
Conn.Open()
If Conn.State = ConnectionState.Open Then
Try
Dim Cmdselect As New OleDbCommand("SELECT * FROM ARTICLE", Conn)
dgrArticle.DataSource = Cmdselect.ExecuteReader
dgrArticle.DataBind()
Catch ex As Exception
'Error handling here
Finally
Conn.Close()
End Try
End If
End If
Jared
"Cemal Karademir" <c.karademir@zonnet.nl> wrote in message
news:%23DFpatVcEHA.996@TK2MSFTNGP12.phx.gbl...
> Okay, I did evrything you said, but now i get an error message:
> System.ArgumentOutOfRangeException: .......
>
> 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="System.Data.OleDb" %>
> <script runat="server">
>
> Sub Page_Load
> dim SQLString as string="Select * from ARTICLE"
> dim Conn as OleDbConnection
> dim ConnectionString as string="Provider=Microsoft.Jet.OLEDB.4.0;
> Ole DB Services=-4; Data Source=C:\SmartSoft.NET\ORSDB.mdb"
> dim Cmdselect as OleDbCommand
> dim dtrArticle as OleDbDataReader
>
> Conn = New OleDbConnection (ConnectionString)
> Conn.Open()
> CmdSelect = New OleDbCommand(SQLString, Conn)
> dtrArticle = CmdSelect.ExecuteReader()
>
> While dtrArticle.Read()
> dgrArticle.DataSource=dtrArticle
> dgrArticle.DataBind()
> End While
>
> dtrArticle.Close()
> Conn.Close()
> End Sub
>
> Private Sub ItemCommand(ByVal source As Object, ByVal e As
> System.Web.UI.WebControls.DataGridCommandEventArgs)
> Dim Item As DataGridItem = CType(e.Item, DataGridItem)
> Dim URL As String
>
> With Item
> URL = "ArticleDetail.aspx?debtorid=" & (Me.txtDebtor.Text.Trim)
> & _
> "&plu=" &
> Server.UrlEncode(CType(.Cells(0).FindControl("lnkPLU"), LinkButton).Text)
> &
> _
> "&description=" & Server.UrlEncode(.Cells(1).Text)
> End With
>
> Response.Redirect(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" autoGenerateColumns="False">
> <Columns>
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:LinkButton id="lnkPLU" runat="server">
> <%#DataBinder.Eval(Container.DataItem,
> "PLU")%>
> </asp:LinkButton>
> <%#DataBinder.Eval(Container.DataItem,
> "DESCRIPTION")%>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> </p>
> </form>
> </body>
> </html>
>
>
- Next message: Jared: "Re: Reading a http page"
- Previous message: JIM.H.: "number of row returned"
- In reply to: Cemal Karademir: "Re: Passing parameter from textbox"
- Next in thread: Cemal Karademir: "Re: Passing parameter from textbox"
- Reply: Cemal Karademir: "Re: Passing parameter from textbox"
- Messages sorted by: [ date ] [ thread ]