Isaac
asked on
'Microsoft.SharePoint.SPList.GetItemById(int)' has some invalid arguments
The error below points to this line in my code:
SPListItem item = sourceList.GetItemById(hdI D);
error CS1502: The best overloaded method match for 'Microsoft.SharePoint.SPLi st.GetItem ById(int)' has some invalid arguments
Any ideas. See a piece of code below.
SPListItem item = sourceList.GetItemById(hdI
error CS1502: The best overloaded method match for 'Microsoft.SharePoint.SPLi
Any ideas. See a piece of code below.
foreach (GridViewRow row in GridView1.Rows)
{
HiddenField hdID = (HiddenField)row.FindControl("hdID");
CheckBox complete = (CheckBox)row.FindControl("complete");
if (complete.Checked)
{
msg.Text += "GRIDVIEW LOOP -- hdID #: " + hdID.Value + "<br />";
SPListItem item = sourceList.GetItemById(hdID);
byte[] fileBytes = item.File.OpenBinary();
string destUrl = destList.RootFolder.Url + "/" + item.File.Name;
SPFile destFile = destList.RootFolder.Files.Add(destUrl, fileBytes, true /*overwrite*/);
SPListItem destItem = destFile.Item;
destItem["STATUS"] = "REROUTE";
destItem["CASE NUMBER"] = "CASE NUMBER";
destItem["PRIORITY"] = "Y";
destItem["PRIORITY CODE"] = "PRIORITY CODE";
destItem["COMPLETE"] = "YES";
destItem.Update();
}
}
ASKER
Now I get this error:
error CS1502: The best overloaded method match for 'int.Parse(string)' has some invalid arguments
error CS1502: The best overloaded method match for 'int.Parse(string)' has some invalid arguments
replace
SPListItem item = sourceList.GetItemById(hdI D);
with
SPListItem item = sourceList.GetItemById(int .Parse(hdI D.toString ()));
SPListItem item = sourceList.GetItemById(hdI
with
SPListItem item = sourceList.GetItemById(int
ASKER
Now I get this error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumb er(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7471335
System.Number.ParseInt32(S tring s, NumberStyles style, NumberFormatInfo info) +119
System.Int32.Parse(String s) +23
ASP._controltemplates_webu sercontrol _ascx.Butt on1_Click( Object sender, EventArgs e) in c:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\CON TROLTEMPLA TES\WebUse rControl.a scx:60
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +111
System.Web.UI.WebControls. Button.Rai sePostBack Event(Stri ng eventArgument) +110
System.Web.UI.WebControls. Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +10
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePo stBackEven t(NameValu eCollectio n postData) +36
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +1565
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumb
System.Number.ParseInt32(S
System.Int32.Parse(String s) +23
ASP._controltemplates_webu
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
This means that your Grid does not pass the value in that cell hdID
that could be a java scripting limiation .
I suggest you trace at this line and check the values at run time
Best of luck.
that could be a java scripting limiation .
I suggest you trace at this line and check the values at run time
Best of luck.
ASKER
GeorgeGerques,
I did a view source on the page before clicking submit and copied this piece of source code on one of the controls:
<input type="hidden" name="ctl00$m$g_8198334b_f 124_40b9_a 51e_787dd5 b05a8d$ctl 00$GridVie w1$ctl02$h dID" id="ctl00_m_g_8198334b_f12 4_40b9_a51 e_787dd5b0 5a8d_ctl00 _GridView1 _ctl02_hdI D" value="2" />
Am I writing the right code to retrieve "hdID"?
I did a view source on the page before clicking submit and copied this piece of source code on one of the controls:
<input type="hidden" name="ctl00$m$g_8198334b_f
Am I writing the right code to retrieve "hdID"?
replace
SPListItem item = sourceList.GetItemById(hdI
with
SPListItem item = sourceList.GetItemById(int
ASKER
That did not work but this did,
SPListItem item = sourceList.GetItemById(Con vert.ToInt 32((hdID.V alue)));
Thanks for leading me in the right direction.
SPListItem item = sourceList.GetItemById(Con
Thanks for leading me in the right direction.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
is acutaly a String
So you need to cast to an int
replace
SPListItem item = sourceList.GetItemById(hdI
with
SPListItem item = sourceList.GetItemById(int
Best of luck