Results 1 to 33 of 33

Thread: [RESOLVED] linkbutton cross page posting error

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Resolved [RESOLVED] linkbutton cross page posting error

    hey

    I have a linkbutton in gridview itemtemplate whenever i post to other page an error shows

    ERROR
    DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID'


    vb Code:
    1. Line 33:                     <ItemTemplate>
    2. Line 34:                         <asp:LinkButton ID="LinkButton2" runat="server" Text='<%# Eval("pk_ddlvryMasterID") %>' PostBackUrl ='<%# "~/Details.aspx?ID="+Eval("ID")  %> ' OnClick="LinkButton2_Click"></asp:LinkButton>
    3. Line 35:                     </ItemTemplate>

  2. #2
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: linkbutton cross page posting error

    please have a look at the msdn regarding the Eval() and Bind()

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    Hello,

    If I had to guess, I would say that this:

    Code:
    Eval("ID")
    Is causing your problem?

    Are you actually retrieving a field from a Database, that has the name of ID?

    Gary

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    @gep

    Yes. The gridview datasource contain a select query "Select pk_ddlvryMasterID as ID ,pk_ddlvryNO,lpono from qDDlvryMaster".

    I was trying to follow the sample : http://csharpdotnetfreak.blogspot.co...erystring.html for cross page posting but I keep rounding in the error.
    Last edited by jlbantang; Jul 18th, 2010 at 10:21 AM.

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    Hey,

    In which case, this:

    Code:
    Eval("pk_ddlvryMasterID")
    Shouldn't work.

    Can you show the full markup for the GridView, and also the DataSource, assuming you are using a SqlDataSource.

    Gary

  6. #6
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: linkbutton cross page posting error

    try this:

    Code:
    Eval("pk_ddlvryMasterID")
    i say this since i think "ID" is not the actual column name that you have used in your database design........in face its an alias name to the column name "pk_ddlvryMasterID"

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    Quote Originally Posted by jlbantang View Post
    I was trying to follow the sample : http://csharpdotnetfreak.blogspot.co...erystring.html for cross page posting but I keep rounding in the error.
    Again, can you show the code that you are using, not the code that you have have taken and modified.

    Gary

  8. #8
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: linkbutton cross page posting error

    hay jlbantang,
    there is no help can be provided with out showing the code.
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  9. #9
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: linkbutton cross page posting error

    one more thing:the link you showed it seems that they are binding the DataGrid in the designer,so you have to learn of how to do this by watching some "How Do I" videos which you will find in the Microsoft website.
    Personally,from my point,i always want to do things by coding and had never relied on the designer yet in cases such as binding the DataGrid or DropDownList or some other controls with the DataSource in the designer.
    Now the choice is upto yours whether you want to do everything in the designer or you want to do it via writing some code

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    vb Code:
    1. <form id="form1" runat="server">
    2.        
    3.         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
    4.             <Columns>
    5.                <asp:TemplateField HeaderText="pk_ddlvryMasterID">
    6.                <ItemTemplate>
    7.                <asp:LinkButton ID="lnkname" runat="server" Text='<%# Eval("pk_ddlvryMasterID") %>' PostBackUrl='<%# "~/Details.aspx?ID="+Eval("ID") %>' OnClick="lnkname_Click"></asp:LinkButton>
    8.                </ItemTemplate>
    9.                </asp:TemplateField>
    10.                
    11.                
    12.                 <asp:BoundField DataField="pk_ddlvryNO" HeaderText="pk_ddlvryNO" SortExpression="pk_ddlvryNO" />
    13.                
    14.             </Columns>
    15.         </asp:GridView>
    16.         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:direct_deliveryConnectionString %>"
    17.             SelectCommand="Select pk_ddlvryMasterID as ID ,pk_ddlvryNO  from qDDlvryMaster">
    18.         </asp:SqlDataSource>
    19.     </form>

    @tommy
    When i tried Eval("pk_ddlvryMasterID") it give me the same error. Also I'm interested seeing your sample if you can provide one for me. Im checking MS HOW TOs for additional guide.

    Thanks

  11. #11
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    Hey jlbantang,

    Ok, so from the SelectCommand for you SqlDataSource, you are doing this:

    Code:
    Select pk_ddlvryMasterID as ID ,pk_ddlvryNO  from qDDlvryMaster
    This means that you will have access to only the following two fields

    • ID
    • pk_ddlvryNO


    Which means that this:

    Code:
    <asp:LinkButton ID="lnkname" runat="server" Text='<&#37;# Eval("pk_ddlvryMasterID") %>' PostBackUrl='<%# "~/Details.aspx?ID="+Eval("ID") %>' OnClick="lnkname_Click"></asp:LinkButton>
    Is incorrect. Try the following:

    Code:
    <asp:LinkButton ID="lnkname" runat="server" Text='<%# Eval("ID") %>' PostBackUrl='<%# "~/Details.aspx?ID="+Eval("ID") %>' OnClick="lnkname_Click"></asp:LinkButton>
    Although, I am still not convinced that this is correct either, based on the error message that you were getting in your first post.

    If this doesn't work, try this:

    Code:
    <asp:LinkButton ID="lnkname" runat="server" Text='<%# Eval("pk_ddlvryMasterID") %>' PostBackUrl='<%# "~/Details.aspx?ID="+Eval("pk_ddlvryMasterID") %>' OnClick="lnkname_Click"></asp:LinkButton>
    Gary

  12. #12
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: linkbutton cross page posting error

    Quote Originally Posted by jlbantang View Post
    hey

    I have a linkbutton in gridview itemtemplate whenever i post to other page an error shows

    ERROR
    DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID'


    vb Code:
    1. Line 33:                     <ItemTemplate>
    2. Line 34:                         <asp:LinkButton ID="LinkButton2" runat="server" Text='<%# Eval("pk_ddlvryMasterID") %>' PostBackUrl ='<%# "~/Details.aspx?ID="+Eval("ID")  %> ' OnClick="LinkButton2_Click"></asp:LinkButton>
    3. Line 35:                     </ItemTemplate>

    Normally when the data is bind with the gridview it will call the Raise the Row for Header, Datarow and Footer.

    I would suggest to handle this in the code Behind event as


    Code:
     Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
            'Check for datarow
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim ctl As LinkButton = TryCast(e.Row.Cells(0).Controls(0), LinkButton) 'Get the Link Button control
                If Not ctl Is Nothing Then
                    'Set the text
                    ctl.Text = e.Row.Cells(0).Text
                    'Assign the Url
                    ctl.PostBackUrl = "set the url"
                End If
                ctl = Nothing
            End If
        End Sub
    Please mark you thread resolved using the Thread Tools as shown

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    @gep

    An error return:
    Input string was not in a correct format

    for the code
    [CODE]
    <asp:LinkButton ID="lnkname" runat="server" Text='<&#37;# Eval("ID") %>' PostBackUrl='<%# "~/Details.aspx?ID="+Eval("ID") %>' OnClick="lnkname_Click"></asp:LinkButton>


    I get an error:
    DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'pk_ddlvryMasterID'

    Code:
    <asp:LinkButton ID="lnkname" runat="server" Text='<%# Eval("pk_ddlvryMasterID") %>' PostBackUrl='<%# "~/Details.aspx?ID="+Eval("pk_ddlvryMasterID") %>' OnClick="lnkname_Click"></asp:LinkButton>

    @danasegarane

    I received the same error from the above. BTW do I need to add the postback url in linkbutton or is it the code behind takes the posting?

  14. #14
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: linkbutton cross page posting error

    Did You try the code posted by me ?
    Please mark you thread resolved using the Thread Tools as shown

  15. #15
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    Hold up...

    Where, and when, did you get this error?

    Input string was not in a correct format
    Gary

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    @danasegarane

    yes but it did not do anything. the page post back to itsel.

    vb Code:
    1. <form id="form1" runat="server">
    2.         &nbsp;<asp:GridView ID="GridView1" runat="server" AllowPaging="True">
    3.             <Columns>
    4.                 <asp:TemplateField HeaderText="ID">
    5.                     <ItemTemplate>
    6.                         <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("ID") %>' ></asp:LinkButton>
    7.                     </ItemTemplate>
    8.                 </asp:TemplateField>
    9.             </Columns>
    10.         </asp:GridView>
    11.         <br />
    12.         <br />
    13.         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:direct_deliveryConnectionString %>"
    14.             SelectCommand="Select pk_ddlvryMasterID as ID ,pk_ddlvryNO  from qDDlvryMaster">
    15.         </asp:SqlDataSource>
    16.     </form>

    vb Code:
    1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    2.         GridView1.DataSource = SqlDataSource1
    3.         GridView1.DataBind()
    4.     End Sub
    5.  
    6.     Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
    7.         GridView1.PageIndex = e.NewPageIndex
    8.         GridView1.DataBind()
    9.     End Sub
    10.  
    11.     Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    12.         'Check for datarow
    13.         If e.Row.RowType = DataControlRowType.DataRow Then
    14.             Dim ctl As LinkButton = TryCast(e.Row.Cells(0).Controls(0), LinkButton) 'Get the Link Button control
    15.             If Not ctl Is Nothing Then
    16.                 'Set the text
    17.                 ctl.Text = e.Row.Cells(0).Text
    18.                 'Assign the Url
    19.                 ctl.PostBackUrl = "default2.aspx?ID=" & ctl.Text.ToString
    20.             End If
    21.             ctl = Nothing
    22.         End If

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    @gep

    Im kinda lost with the sample and I redo everything. The update is in post #16.
    Currently the page do not received errors even firing the link button. I tried following danasegarane codes but it does not cross posting.

    Thanks.

  18. #18
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    Okay, at this point, I would suggest you take a complete step back.

    Decide on which approach you want to take, either putting the necessary code in the markup, i.e. using Eval, or putting it in the code behind, as Dana suggested.

    If I had a preference, I would go with Dana's code.

    Gary

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    Alright, so i decided to follow dana walkthrough with some flashy codes .

  20. #20
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    Good stuff. So does that mean you have got it working, or are you still having issues?

    Gary

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    @Gary

    The link button does not posting to target page instead its posting back to itself. I already added dana code. Im not sure if it right thou:

    vb Code:
    1. If e.Row.RowType = DataControlRowType.DataRow Then
    2.  
    3.             Dim ctl As LinkButton = TryCast(e.Row.Cells(0).Controls(0), LinkButton) 'Get the Link Button control
    4.             If Not ctl Is Nothing Then
    5.                 'Set the text
    6.                 ctl.Text = e.Row.Cells(0).Text
    7.                 'Assign the Url
    8.                 ctl.PostBackUrl = "default2.aspx?ID=" & ctl.Text.ToString
    9.             End If
    10.            ctl = Nothing
    11.         End If

  22. #22
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    If you set a breakpoint on this line:

    Code:
    ctl.PostBackUrl = "default2.aspx?ID=" & ctl.Text.ToString
    Does it get hit?

    Gary

  23. #23
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: linkbutton cross page posting error

    From MSDN

    Use the LinkButton control to create a hyperlink-style button on the Web page. The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control. If you want to link to another Web page when the control is clicked, consider using the HyperLink control.
    Please mark you thread resolved using the Thread Tools as shown

  24. #24

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    Quote Originally Posted by gep13 View Post
    If you set a breakpoint on this line:

    Code:
    ctl.PostBackUrl = "default2.aspx?ID=" & ctl.Text.ToString
    Does it get hit?

    Gary
    No, its not hitting the code. I tried to move it to other method but Im getting error in

    vb Code:
    1. If e.Row.RowType = DataControlRowType.DataRow Then

  25. #25
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    Ok, if this line isn't getting hit:

    Code:
    ctl.PostBackUrl = "default2.aspx?ID=" & ctl.Text.ToString
    That is why you are not posting back to the right page.

    When you say you got an "error", can you elaborate?

    Gary

  26. #26

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    Gridview_RowCommand() return an error

    e.row.rowtype is not a member of GridviewCommandEventArgs

  27. #27
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    Hold on a minute...

    Where exactly are you putting the above code? As per Dana's example, you should be putting it in the RowDataBound event of the GridView.

    Gary

  28. #28
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: linkbutton cross page posting error

    Quote Originally Posted by jlbantang View Post
    No, its not hitting the code. I tried to move it to other method but Im getting error in

    vb Code:
    1. If e.Row.RowType = DataControlRowType.DataRow Then
    What is the other method. Post it
    Please mark you thread resolved using the Thread Tools as shown

  29. #29

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    Exactly it is in RowDataBound().

    But since the code is not being hit when I do the page break I tried to move it somewhere else.

  30. #30
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: linkbutton cross page posting error

    Hey,

    If the break point isn't getting hit, it is because something in that event handler is stopping it from getting hit.

    Put the break point on the first line of the event handler, does it get hit? If so, start stepping through your code. Bear in mind that this event handler will get called multiple times before the page finishes loading.

    Gary

  31. #31

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: linkbutton cross page posting error

    OMG IM so deeply tangled...

    Finally i found another sample that really works. And these sample uses hyperlinkfield as dana suggested.
    Also I added filtering on it. Next thing to do is perform update.

    vb Code:
    1. <body>
    2.     <form id="form1" runat="server">
    3.     <div>
    4.     <asp:GridView ID="GridView1" runat="server"
    5.               AutoGenerateColumns="False"
    6.               DataSourceID="SqlDataSource1" AllowPaging="True">
    7. <Columns>
    8. <asp:HyperLinkField DataNavigateUrlFields="ID,pk_ddlvryNO,lpono" DataNavigateUrlFormatString="edit_delivery.aspx?id={0}" Text=">" />
    9.  
    10. <asp:BoundField DataField="pk_ddlvryNO" HeaderText="pk_ddlvryNO"
    11.                 SortExpression="pk_ddlvryNO" />
    12.                
    13. <asp:BoundField DataField="lpono" HeaderText="lpono"            
    14.                 SortExpression="lpono" />
    15. </Columns>
    16. </asp:GridView>
    17.         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    18.         <asp:Button ID="Button1" runat="server" Text="Button" />
    19.         <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/img/edit.gif" /><br />
    20.     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:direct_deliveryConnectionString %>"
    21.             SelectCommand="Select pk_ddlvryMasterID as ID ,pk_ddlvryNO,lpono  from qDDlvryMaster">
    22.         </asp:SqlDataSource>
    23.     </div>
    24.     </form>
    25. </body>
    Im posting that in different field as it not fitting to the thread.

    Thanks gary.

    Thanks all.

  32. #32
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] linkbutton cross page posting error

    Hey,

    Yip, this is certainly another way to achieve the same thing.

    When you get some time, I would still suggest that you go back and have a look at doing the work in your server side code, it does work, and in my opinion, it is the correct place to do it.

    Gary

  33. #33
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] linkbutton cross page posting error

    Happy to see it works
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width