Jump to content

updatepanel woes


kreplech

Recommended Posts

hello all,i am having trouble learning how to use the ajax updatepanel. when i try to update a row, i receive the message "No parameterless constructor is defined for this object"... i am just learning, and completely clueless...Anyway, just hoping somebody can explain this to me in newbie-speak. I'm trying to get the gridview row to let the user update only the statusfk and paperTitle fields. so far, when EDIT is clicked, the proper controls are displayed, however, the aforementioned error occurs when UPDATE is clicked. Any ideas?My code follows:asp:

<asp:Label ID="lblTest" runat="server" Text="Label"></asp:Label>		<ajax:UpdatePanel ID="upPapers" runat="server">			<ContentTemplate>				<div style="width:525px;">					<asp:GridView ID="gvPapers" ShowHeader="true" runat="server" AutoGenerateColumns="False" DataKeyNames="paperid" DataSourceID="odsPapers">						<Columns>							<asp:TemplateField>								<ItemTemplate>									 <asp:LinkButton Text="Edit" CommandName="Edit" CausesValidation="false" runat="server"										ID="btEdit" /> 								</ItemTemplate>								<EditItemTemplate>									<asp:LinkButton Text="Update" CommandName="Update" CausesValidation="true" runat="server"										ID="btUpdate" /> 									<asp:LinkButton Text="Cancel" CommandName="Cancel" CausesValidation="false" runat="server"										ID="btCancel" />								</EditItemTemplate>							</asp:TemplateField>							<asp:CheckBoxField DataField="statusfk" HeaderText="Status" SortExpression="statusfk" />							<asp:TemplateField>								<ItemTemplate>									<asp:Label ID="lblFileType" Text='<%# Eval("FileTyp") %>' runat="server" /> 								</ItemTemplate>															</asp:TemplateField>							<asp:TemplateField HeaderText="PaperTitle" SortExpression="PaperTitle">								<ItemTemplate>									<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Bind("PaperTitle") %>' NavigateUrl='<%# "http://galileo2.rand.org/candidate/papers/" + Eval("FileURL") %>' />   								</ItemTemplate>								<EditItemTemplate>									<asp:TextBox ID="txtPaperTitle" runat="server" Text='<%# Bind("PaperTitle") %>' Rows="2" TextMode="MultiLine" style="width:350px; font:11px arial;" ></asp:TextBox>								</EditItemTemplate>							</asp:TemplateField>							<asp:TemplateField>								<ItemTemplate>									<asp:Label ID="lblFileSize" Text='<%# Eval("FileSiz") %>' runat="server" style="white-space:nowrap" /> 								</ItemTemplate>															</asp:TemplateField>						</Columns>					</asp:GridView>				</div>			</ContentTemplate>		</ajax:UpdatePanel>

any help is truly appreciated.Thanks,M

Link to comment
Share on other sites

any code behind is completely ignored as the update link in the gridview produces only the "No parameterless constructor is defined for this object" error everytime it is clicked. currently all the code is commented out. is there a particular event i need to tie to the update button - or gridview?

Link to comment
Share on other sites

I've never used the .NET ajax solutions - I either tend to write my own or use a different solution - so I don't have any experience with this UpdatePanel control.However, you say the problem occurs when you click the LinkButton. Does it happen only for the Update LinkButton or does it also happen with the Edit and Cancel buttons as well? You say you commented out your code in the code-behind, did you comment out the Page_Load method as well?Are you developing this with Visual Studio? If so, have you tried running this in debug mode and using stop points to see where, exactly, this is failing?

Link to comment
Share on other sites

OK - so i realized a couple of things this morning that my eyes were too tired to see last night.First of all - I hadn't formed my objectdatasource correctly... no update parms... ANYWAY, so now it looks like:

<asp:ObjectDataSource ID="odsPapers" runat="server" OldValuesParameterFormatString="original_{0}" 			SelectMethod="GetData"			TypeName="selectPapersTableAdapters.tbl_CTS_PapersTableAdapter" UpdateMethod="Update">			<SelectParameters>				<asp:SessionParameter Name="APPLID" SessionField="RANDID" Type="String" />			</SelectParameters>			<UpdateParameters>				<asp:Parameter Name="paperid" Type="Int32" />				<asp:Parameter Name="statusfk" Type="Boolean" />				<asp:Parameter Name="paperTitle" Type="String" />			</UpdateParameters>		</asp:ObjectDataSource>

Also, I've added the primary key of my table as a hidden control... maybe not necessary since the gridview has it in the datakeynames? anyway, so now it looks like:

<ajax:UpdatePanel ID="upPapers" runat="server">			<ContentTemplate>				<div style="width:525px;">					<asp:GridView ID="gvPapers" ShowHeader="true" runat="server" AutoGenerateColumns="False" DataKeyNames="paperid" DataSourceID="odsPapers">						<Columns>							<asp:TemplateField>								<ItemTemplate>									 <asp:LinkButton Text="Edit" CommandName="Edit" CausesValidation="false" runat="server"										ID="btEdit" /> 								</ItemTemplate>								<EditItemTemplate>									<asp:LinkButton Text="Update" CommandName="Update" CausesValidation="true" runat="server"										ID="btUpdate" /> 									<asp:LinkButton Text="Cancel" CommandName="Cancel" CausesValidation="false" runat="server"										ID="btCancel" />								</EditItemTemplate>							</asp:TemplateField>							<asp:CheckBoxField DataField="statusfk" HeaderText="Status" SortExpression="statusfk" />							<asp:TemplateField>								<ItemTemplate>									<asp:Label ID="lblFileType" Text='<%# Eval("FileTyp") %>' runat="server" /> 								</ItemTemplate>															</asp:TemplateField>							<asp:TemplateField HeaderText="PaperTitle" SortExpression="PaperTitle">								<ItemTemplate>									<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Bind("PaperTitle") %>' NavigateUrl='<%# "http://galileo2.rand.org/candidate/papers/" + Eval("FileURL") %>' />   								</ItemTemplate>								<EditItemTemplate>									<asp:TextBox ID="txtPaperTitle" runat="server" Text='<%# Bind("PaperTitle") %>' Rows="2" TextMode="MultiLine" style="width:350px; font:11px arial;" ></asp:TextBox>								</EditItemTemplate>							</asp:TemplateField>							<asp:TemplateField>								<ItemTemplate>									<asp:Label ID="lblFileSize" Text='<%# Eval("FileSiz") %>' runat="server" style="white-space:nowrap" /> 									<asp:HiddenField ID="paperid" Value='<%# Eval("paperid") %>' runat="server" />								</ItemTemplate>															</asp:TemplateField>						</Columns>					</asp:GridView>				</div>			</ContentTemplate>		</ajax:UpdatePanel>

finally, i found that my updatepanel did not have any command text associated with the update method... so i've filled in the proper update statement (UPDATE dbo.tbl_CTS_Papers SET statusfk = @statusfk, PaperTitle = @paperTitle WHERE (paperid = @paperid))so, now i get a different error:ObjectDataSource 'odsPapers' could not find a non-generic method 'Update' that has parameters: statusfk, PaperTitle, original_paperid.oddly, i have no reference to a var named original_paperid anywhere that i can find... nor have i ever that i can remember... very confusing.any ideas?

Link to comment
Share on other sites

Having never used this control, nor having ever used any datasource except for those defined in the code-behind, I can only guess at this. It looks like the value you store in "OldValuesParameterFormatString" is appending the "original_" to the Parameters that you specify in the UpdateParameters section: "paperid", when run through the format string of "original_{0}" becomes "original_paperid".

Link to comment
Share on other sites

Ah, you got it working! Glad to hear it.If you are new to ASP.NET and are just learning, I would, personally, recommend that you start to rely more heavily on code-behind rather than doing all of this in the ASPX using controls. You'll find that you have much more control over everything and, as your pages/forms get more and more complicated, you'll find that it is much easier to keep track of everything when you build it in the code-behind rather than in the page itself.In the case of the GridView, if you set up the DataSource in the code behind you could then, programmatically, add the DataSource to the GridView:

gvPapers.DataSource = MyDataSource;gvPapars.DataBind();

Again, this is only my opinion. :)

Link to comment
Share on other sites

Using code behind was my first instinct as, i agree, i feel handcuffed without accessing the code... but my biggest obstacle so far - and you've helped me with this at least once before - is accessing variables using code behind. it seems like every control requires different syntax. for example, the datalist you helped me with used the syntax:

string fileType = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "fileTyp"));

to get the value of a hidden control within a datalist... but required

((Image)e.Item.FindControl("fileIcon")).ImageUrl = "images/pdf.gif";

to access the image control from the same datalist... i don't understand the difference... and neither of them worked for a gridview.can you recommend a tutorial or reference site for this type of stuff. is there a particularly good book for C#? I'm such a whiny newb...Thanks again for all the help.M

Link to comment
Share on other sites

my biggest obstacle so far ... is accessing variables using code behind. it seems like every control requires different syntax.
While it's true that every class (e.g. Controls) has its own set of members (properties, methods, etc.), it's also true that every control has different attributes that you need to use in the page.For the Image control, you could either specify the ImageUrl in the page:
<asp:Image id="Image1" ImageUrl="SomeImage.gif" runat="server" />

Or you could specify it in the code-behind:

Image1.ImageUrl = "SomeImage.gif";

For the most part, the attribute name mirrors the property name in the tag.

can you recommend a tutorial or reference site for this type of stuff. is there a particularly good book for C#?
Because .NET is a Microsoft product, the single most comprehensive resource is the MSDN site. Typically it's the first result when you do a Google search. For instance, the Google search for "GridView" returns:http://msdn2.microsoft.com/en-us/library/s...s.gridview.aspxIf you haven't ever used this site for a reference, you might want to get familiar with it - you'll use it a lot. If you scroll down to the bottom of that page to the "See Also Reference" section, you'll see a link for "GridView Members". It's the "Members" page that will show you all the properties, methods, etc. that belong to the GridView control.Then, most of the time, if you click on one of the Members (e.g. "DataSource"), you'll get an example of how to use it in four or five different languages.If you can't find information there, when I was first learning, I turned to http://www.codeproject.com/. They had a bunch of articles on all sorts of topics that typically help quite a bit.You can also post your questions here.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...