|
-
Jul 18th, 2010, 08:17 AM
#1
Thread Starter
Fanatic Member
[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:
Line 33: <ItemTemplate>
Line 34: <asp:LinkButton ID="LinkButton2" runat="server" Text='<%# Eval("pk_ddlvryMasterID") %>' PostBackUrl ='<%# "~/Details.aspx?ID="+Eval("ID") %> ' OnClick="LinkButton2_Click"></asp:LinkButton>
Line 35: </ItemTemplate>
-
Jul 18th, 2010, 09:22 AM
#2
Fanatic Member
Re: linkbutton cross page posting error
please have a look at the msdn regarding the Eval() and Bind()
-
Jul 18th, 2010, 09:24 AM
#3
Re: linkbutton cross page posting error
Hello,
If I had to guess, I would say that this:
Is causing your problem?
Are you actually retrieving a field from a Database, that has the name of ID?
Gary
-
Jul 18th, 2010, 10:12 AM
#4
Thread Starter
Fanatic Member
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.
-
Jul 18th, 2010, 10:19 AM
#5
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
-
Jul 18th, 2010, 10:20 AM
#6
Fanatic Member
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"
-
Jul 18th, 2010, 10:25 AM
#7
Re: linkbutton cross page posting error
 Originally Posted by jlbantang
Again, can you show the code that you are using, not the code that you have have taken and modified.
Gary
-
Jul 18th, 2010, 04:34 PM
#8
Frenzied Member
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 
-
Jul 18th, 2010, 08:21 PM
#9
Fanatic Member
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
-
Jul 19th, 2010, 12:12 AM
#10
Thread Starter
Fanatic Member
Re: linkbutton cross page posting error
vb Code:
<form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"> <Columns> <asp:TemplateField HeaderText="pk_ddlvryMasterID"> <ItemTemplate> <asp:LinkButton ID="lnkname" runat="server" Text='<%# Eval("pk_ddlvryMasterID") %>' PostBackUrl='<%# "~/Details.aspx?ID="+Eval("ID") %>' OnClick="lnkname_Click"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="pk_ddlvryNO" HeaderText="pk_ddlvryNO" SortExpression="pk_ddlvryNO" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:direct_deliveryConnectionString %>" SelectCommand="Select pk_ddlvryMasterID as ID ,pk_ddlvryNO from qDDlvryMaster"> </asp:SqlDataSource> </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
-
Jul 19th, 2010, 01:17 AM
#11
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
Which means that this:
Code:
<asp:LinkButton ID="lnkname" runat="server" Text='<%# 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
-
Jul 19th, 2010, 01:38 AM
#12
Re: linkbutton cross page posting error
 Originally Posted by jlbantang
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:
Line 33: <ItemTemplate>
Line 34: <asp:LinkButton ID="LinkButton2" runat="server" Text='<%# Eval("pk_ddlvryMasterID") %>' PostBackUrl ='<%# "~/Details.aspx?ID="+Eval("ID") %> ' OnClick="LinkButton2_Click"></asp:LinkButton>
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
-
Jul 19th, 2010, 02:12 AM
#13
Thread Starter
Fanatic Member
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='<%# 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?
-
Jul 19th, 2010, 02:16 AM
#14
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
-
Jul 19th, 2010, 02:22 AM
#15
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
-
Jul 19th, 2010, 02:25 AM
#16
Thread Starter
Fanatic Member
Re: linkbutton cross page posting error
@danasegarane
yes but it did not do anything. the page post back to itsel.
vb Code:
<form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AllowPaging="True"> <Columns> <asp:TemplateField HeaderText="ID"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("ID") %>' ></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <br /> <br /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:direct_deliveryConnectionString %>" SelectCommand="Select pk_ddlvryMasterID as ID ,pk_ddlvryNO from qDDlvryMaster"> </asp:SqlDataSource> </form>
vb Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load GridView1.DataSource = SqlDataSource1 GridView1.DataBind() End Sub Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging GridView1.PageIndex = e.NewPageIndex GridView1.DataBind() End Sub 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 = "default2.aspx?ID=" & ctl.Text.ToString End If ctl = Nothing End If
-
Jul 19th, 2010, 02:35 AM
#17
Thread Starter
Fanatic Member
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.
-
Jul 19th, 2010, 02:38 AM
#18
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
-
Jul 19th, 2010, 02:58 AM
#19
Thread Starter
Fanatic Member
Re: linkbutton cross page posting error
Alright, so i decided to follow dana walkthrough with some flashy codes .
-
Jul 19th, 2010, 03:03 AM
#20
Re: linkbutton cross page posting error
Good stuff. So does that mean you have got it working, or are you still having issues?
Gary
-
Jul 19th, 2010, 04:15 AM
#21
Thread Starter
Fanatic Member
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:
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 = "default2.aspx?ID=" & ctl.Text.ToString End If ctl = Nothing End If
-
Jul 19th, 2010, 05:11 AM
#22
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
-
Jul 19th, 2010, 05:46 AM
#23
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
-
Jul 19th, 2010, 08:06 AM
#24
Thread Starter
Fanatic Member
Re: linkbutton cross page posting error
 Originally Posted by gep13
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:
If e.Row.RowType = DataControlRowType.DataRow Then
-
Jul 19th, 2010, 08:21 AM
#25
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
-
Jul 19th, 2010, 08:41 AM
#26
Thread Starter
Fanatic Member
Re: linkbutton cross page posting error
Gridview_RowCommand() return an error
e.row.rowtype is not a member of GridviewCommandEventArgs
-
Jul 19th, 2010, 08:47 AM
#27
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
-
Jul 19th, 2010, 08:49 AM
#28
Re: linkbutton cross page posting error
 Originally Posted by jlbantang
No, its not hitting the code. I tried to move it to other method but Im getting error in
vb Code:
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
-
Jul 19th, 2010, 08:51 AM
#29
Thread Starter
Fanatic Member
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.
-
Jul 19th, 2010, 08:56 AM
#30
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
-
Jul 20th, 2010, 12:53 AM
#31
Thread Starter
Fanatic Member
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:
<body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True"> <Columns> <asp:HyperLinkField DataNavigateUrlFields="ID,pk_ddlvryNO,lpono" DataNavigateUrlFormatString="edit_delivery.aspx?id={0}" Text=">" /> <asp:BoundField DataField="pk_ddlvryNO" HeaderText="pk_ddlvryNO" SortExpression="pk_ddlvryNO" /> <asp:BoundField DataField="lpono" HeaderText="lpono" SortExpression="lpono" /> </Columns> </asp:GridView> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/img/edit.gif" /><br /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:direct_deliveryConnectionString %>" SelectCommand="Select pk_ddlvryMasterID as ID ,pk_ddlvryNO,lpono from qDDlvryMaster"> </asp:SqlDataSource> </div> </form> </body>
Im posting that in different field as it not fitting to the thread.
Thanks gary.
Thanks all.
-
Jul 20th, 2010, 01:00 AM
#32
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
-
Jul 20th, 2010, 01:22 AM
#33
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|