|
Null is not an integer value. This is why it's failing - as a plain int is not a nullable type, you cannot just parse it, you should actually use TryParse instead. You need to break your logic up into something that looks a little bit like this:
private int GetValue(TextBox textBox)
{
int output;
if (int.TryParse(textBox.Text, out output))
{
return output;
}
return 0;
}
int lblQtr1 = GetValue(Q1IntProc) + GetValue(Q1IntProj) + GetValue(Q1ExtBSI) + GetValue(Q1ExtCMMI);
|
|
|
|
|
I getting that error that The name 'Q1IntProc' does not exist in the current context.
So I should have an if statement for each field that I am summing? So what goes here textBox.Text?
|
|
|
|
|
I already suggested that you check the variable names that you are using. They appear not to match the names you have set in your ASP page.
|
|
|
|
|
<itemtemplate>
<asp:label id="lblQ1IntProc" text="<%#Eval("Q1IntProc") %>"
="" runat="server">
<itemtemplate>
<asp:label id="lblQ1IntProj" text="<%#Eval("Q1IntProj") %>"
="" runat="server">
<itemtemplate>
<asp:label id="lblQ1ExtBSI" text="<%#Eval("Q1ExtBSI") %>"
="" runat="server">
<itemtemplate>
<asp:label id="lblQ1ExtCMMI" text="<%#Eval("Q1Q1ExtCMMI") %>"
="" runat="server">
It is what I have in my asp. Did I not set it properly?
|
|
|
|
|
Hi, I not sure how to use this code? Please let me know if I need to make changes to it?
|
|
|
|
|
Pete, I not for sure how to use this code. Can you let me know what I need to do? I still getting the error for the 4 fields. The fields do not exist in the current context.
|
|
|
|
|
A quick check would be - just put a debug point on the line throwing the error, and hover (move your mouse pointer over) Q1IntProc , Q1IntProj , Q1ExtBSI and Q1ExtCMMI one by one (or with a quick watch (right click -> Quick Watch)) and check which one's null .
There must be (atleast) one of them which is null. If so, look at corresponding "FindControl" statement and check if the string param you are specifying for the "FindControl" call ("txtQ1IntProc", for instance) does actually represent a valid TextBox in your (GridView's) row.
Hope that helps.
You have just been Sharapova'd.
|
|
|
|
|
I did that and all of them are null.
aspx:
<asp:templatefield headertext="Q1IntProc">
<edititemtemplate>
<asp:textbox id="txtQ1IntProc" text="<%#Eval("Q1IntProc") %>"
="" runat="server">
<itemtemplate>
<asp:label id="lblQ1IntProc" text="<%#Eval("Q1IntProc") %>"
="" runat="server">
<footertemplate>
<asp:textbox id="newQ1IntProc" runat="server">
I changed to my code to TextBox but still getting the null errors:
Qtr1 value is 0 the other 4 are null.
modified 19-Jun-15 3:21am.
|
|
|
|
|
The ids of the textboxes in your ASP file do not (as far as I can see) match the names you are using in your code. Also coding a line such as
int lblQtr1 = int.Parse(Q1IntProc.Text) + int.Parse(Q1IntProj.Text) + int.Parse(Q1ExtBSI.Text) + int.Parse(Q1ExtCMMI.Text);
is asking for trouble. You have no idea what may be in any of the text fields, so if the user enters garbage it will just fail. You shoud use int.TryParse to capture the numeric values, so you can alert the user if any is invalid. You should also assign each value to an individual variable before summing them. That way, you can debug it much more easily.
|
|
|
|
|
Norris Chappell wrote: I changed to my code to TextBox but still getting the null errors: Yes, that should be Label only and not TextBox, my mistake.
Not sure what's wrong here. But in your ASP markup, are you missing an <ItemTemplate> wrapped around the controls? You can also try finding the control in a "Cell" (like row.Cells[N].FindControl(), where N-> index of the container cell).
Not sure it's related, but you can also check the actual IDs of the controls after they are rendered and there's a property "ClientIDMode"(?) of GridView (not sure but I remember to have faced something similar a few years ago when I worked on ASP.NET WebForms) which you can use if there's a mismatch.
Good luck!
You have just been Sharapova'd.
|
|
|
|
|
Hi Everyone I finally figured it out. I didn't need to do it in C# after all. I modified my SQL to sum the fields I needed. I want to thank everyone that contributed.
modified 19-Jun-15 23:37pm.
|
|
|
|
|
I have a dictionary where the key is a DateTime. I need to find the 2 entries in the dictionary that are closest to a given datetime.
So, I have
Dictionary<DateTime, double> columnInfos = new Dictionary<DateTime, double>();
foreach (var activity in activities)
{
DateTime activityDate = activity.ActivityDateTime;
}
I was going to loop through the dictionary, but is that really the best way?> Anyone have a better solution?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Coder (Hired) wrote: I was going to loop through the dictionary, but is that really the best way? The best way depends on your requirements. If there can be a lot of DateTimes and lookup is more frequent than insertion/deletion then a SortedList<TKey, TValue>[^] might provide better performance. Though if you also need lookup by an exact DateTime then you would have to create a custom collection class where you combine a Dictionary with a SortedList to get the best of both (or maybe you can find an existing implementation of that).
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
Hello,
I have a performance problem with my application accessed on an active PowerPoint presentation (2010 version). Datas should readout of a datagrid and automatically entered to a PowerPoint slide which has to be created. Each entry of the DataGrid is written in a separate text box. It is this process that takes a long time. Does anyone knows technology / solution that can make the program much more quicker. Program code is written in C #.
List<Microsoft.Office.Interop.PowerPoint.Shape> ResponsibleTxtbox= new List<Microsoft.Office.Interop.PowerPoint.Shape>();
ResponsibleTxtbox.Add(slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, posLeft, posTop, 0, 0));
ResponsibleTxtbox[j].TextFrame2.WordWrap = MsoTriState.msoFalse;
ResponsibleTxtbox[j].TextFrame2.TextRange.Font.Size = mFontSize;
ResponsibleTxtbox[j].TextFrame2.TextRange.Font.Name = mFontName;
ResponsibleTxtbox[j].Tags.Add("TxtBoxType", "RespTxtBox" + j.ToString());
ResponsibleTxtbox[j].TextFrame2.TextRange.Text = responsiblesNames[j];
Thx in advanced
|
|
|
|
|
The problem is that you're using Office COM Interop to generate the PowerPoint slides. Office Interop is notoriously slow and there's no way to speed it up.
If you're using Office 2007 or higher, you're only other choice is to generate the PowerPoint file directly using the OpenXML SDK[^]. It goes a LOT faster but the learning curve to use the SDK is pretty steep.
|
|
|
|
|
Hello,
I would like to know if you can also edit open presentations with OpenXml? I have read it would not go. Do you know more about it since?
greeting
|
|
|
|
|
If by "edit open presentations" you're talking about using OpenXML to make changes to a presentation that is currently open in PowerPoint and being view and seeing those changes as your code makes them, no.
The OpenXML SDK will only work with files on disk and NOT opened in PowerPoint.
|
|
|
|
|
what can be a possibility to do that? Is there another xml stuff
I like to create new slides in an existing presentation which are filed with textboxes with different data. Like create a formular with c', insert different datas and create new slides out of it. All in a opend presentation
|
|
|
|
|
Member 11775354 wrote: what can be a possibility to do that?
If this is the case, how you're doing it right now is your ONLY option and there is no way to speed it up.
|
|
|
|
|
I know, that there must be a possibility not to usee the com interface, I have seen it, but do not know, how they do it
|
|
|
|
|
If there is, I've never seen nor heard of it.
|
|
|
|
|
have you guys who a very very familar with that stuff to check?
|
|
|
|
|
dataaccesslayer
public SqlDataReader reader(string query)
{
try
{
con1.Open();
cmd = new SqlCommand(query, con1);
dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
con1.Close();
}
return dr;
}
logical layer
public SqlDataReader Product_Gridclick(string id)
{
query = "select pid,pname,pmodel,pprice,sprice,discount,pdescription from product_table where pid=" + "'" + id + "'";
return da.reader(query);
}
presentation layer
string s = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
SqlDataReader dr;
dr = llayer.Product_Gridclick(s);
if (dr.HasRows)
{
while (dr.Read())
{
txtproductid.ReadOnly = false;
txtproductid.Text = dr[0].ToString();
txtproname.Text = dr[1].ToString();
txtpromodel.Text = dr[2].ToString();
txtpurprice.Text = dr[3].ToString();
txtsaleprice.Text = dr[4].ToString();
txtdiscount.Text = dr[5].ToString();
rchdescription.Text = dr[6].ToString();
}
}
Gnanavel Sekar
|
|
|
|
|
The finally in reader closes the connection. This happens before this method returns, so you are opening and closing the reader before you attempt to iterate over the reader.
|
|
|
|