-
[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>
-
Re: linkbutton cross page posting error
please have a look at the msdn regarding the Eval() and Bind()
-
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
-
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.
-
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
-
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"
-
Re: linkbutton cross page posting error
Quote:
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
-
Re: linkbutton cross page posting error
hay jlbantang,
there is no help can be provided with out showing the code.
-
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 :)
-
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
-
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
-
Re: linkbutton cross page posting error
Quote:
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
-
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?
-
Re: linkbutton cross page posting error
Did You try the code posted by me ?
-
Re: linkbutton cross page posting error
Hold up...
Where, and when, did you get this error?
Quote:
Input string was not in a correct format
Gary
-
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
-
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.
-
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
-
Re: linkbutton cross page posting error
Alright, so i decided to follow dana walkthrough with some flashy codes :D.
-
Re: linkbutton cross page posting error
Good stuff. So does that mean you have got it working, or are you still having issues?
Gary
-
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
-
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
-
Re: linkbutton cross page posting error
From MSDN
Quote:
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.
-
Re: linkbutton cross page posting error
Quote:
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
-
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
-
Re: linkbutton cross page posting error
Gridview_RowCommand() return an error
e.row.rowtype is not a member of GridviewCommandEventArgs
-
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
-
Re: linkbutton cross page posting error
Quote:
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 :wave:
-
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.
-
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
-
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.
-
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
-
Re: [RESOLVED] linkbutton cross page posting error