I have an application that was throwing the error message below:
Invalid currentpageindex value. it must be >= 0 and the < pagecount
This issue happens if I go to the second page in my application and then try to filter the results by entering a search term.
After some research I thought I had fixed the issue by adding this line to my code
gridResult.CurrentPageIndex = 0;
So the code block now looks like this:
private void gridResult_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
gridResult.CurrentPageIndex = e.NewPageIndex;
FillGrid(tbSearch.Text);
gridResult.CurrentPageIndex = 0;
}
This stops the original issue with the error I was encountering explained above. However now if I navigate to the second page in my paging and then click to go back to the first page the data is not refreshed it just holds on to the data in the second page.
I have been struggling to find any solution for this, any ideas would be appreciated.
Related
I am kind of newbie and I have an issue with ASP:Button controls.
There is about 60 buttons on the page, typical XAML looks like this:
<asp:Button class="tile" ID="Button1" runat="server" Text="Domains"/>
I need to iterate through all of the buttons on the page to change properties and I don't want to do it one by one.
I've found many suggestions here and there, but nothing works. My code behind is:
for (int i = 1; i < 59; i++)
{
String butt = String.Format("Button{0}", i);
var btn = FindControl(butt);
btn.Visible = false;
}
Error is that there is no object reference. btn is null.
I tried to inspect element in running application and it says ID of element is "MainContent_Button1" - tried that too, does not work. Other thing I tried is
foreach(var button in this.Controls.OfType<Button>())
{
button.Visible = false;
}
I came to conclusion that asp:button is a) not a control of button type b) its ID is somehow generated when the application is run and therefore there is no control with id Button1 to be found.
Can anyone please explain that to me? I'd really like to understand why is it behaving like that and what exactly is the purpose of this behavior.
Thanks
Edit: I even tried to remove the loop completely and modify one specific button using FindControl method. Does not work either.
var btn = FindControl("Button1");
btn.Visible = false;
result: System.NullReferenceException: 'Object reference not set to an instance of an object.'
It looks like you are using a Master Page. Using FindControl on a Master Page works slightly different than on a normal page.You first need to find the correct ContentPlaceHolder in which the Buttons are located and use FindControl on that ContentPlaceHolder.
ContentPlaceHolder cph = Master.FindControl("MainContent") as ContentPlaceHolder;
for (int i = 1; i < 9; i++)
{
String butt = String.Format("Button{0}", i);
var btn = cph.FindControl(butt);
btn.Visible = false;
}
I have a Windows Forms Application I am working on and am using the language C#. I have a Txt file called "UnorderedIDValues.Txt" that I am importing into a DataGrid View. Here is the code I have so far:
private void loadButton_Click(object sender, EventArgs e)
{
if (File.Exists(DATA_FILE_NAME))
fileIn = File.OpenText(DATA_FILE_NAME);
else
{
MessageBox.Show(DATA_FILE_NAME + " does not exist", "Abort Execution",
MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
if (listCountTextBox.ReadInt(out index))
for (index = 1; index <= 1240000; index++)
idList.Add(index);
fileIn.Close();
DisplayIDList(displayDGV);
}
What I am trying to accomplish is: I have a button to load the list into the DataGrid View, which loads just fine, but it's the whole list which isn't what I want. I have an ETextbox that I am wanting to be able to put in a number and only generate that number of values. I feel like I am pretty close, but I just can't wrap my head around writing the correct logic. There are 1,240,000 Values in that text file that are formatted like this: "000-0000"
Any help would be greatly appreciated. Thank You!
I don't know what is the purpose of idList but actually you are reading index value from the TextBox and then you are setting it to 1. And then you cycle till index <= 124000
Change your for loop to the following:
for (i = 1; i <= index; i++)
idList.Add(i);
You can also do it using Linq avoiding the for loop:
idList.addRange(Enumerable.Range(1, index));
Ok this one got me hitting my head on the wall for a while now.
I look at a list of web elements. I access that list like so
foreach (IWebElement link in driver.FindElementsByCssSelector("span.cn.mailbox > a"))
{
// Click at a lot of page and the page will reload eventually
}
The problem is, inside the loop, I need to change pages and stuff but at the end I get back to that page that has the link list.
As soon as I hit the second iteration, I get the following error :
Probably because I changed page and even thought the links in the collection I loop through are the same, the compiler doesn't seem to think it's the exact same collection.
Is there a way around this or a workaround I could use ?
The reason you're getting the exception is because the page the driver.FindElementsByCssSelector is referencing has been reloaded.
Something like this should work:
Create an array of link text. Iterate through the link text array, clicking each link.
string [] links = new string[driver.FindElementsByCssSelector("span.cn.mailbox > a").Count);
int i = 0;
foreach (IWebElement link in driver.FindElementsByCssSelector("span.cn.mailbox > a"))
{
links[i++] = link.Text;
}
for (int i = 0; i < driver.FindElementsByCssSelector("span.cn.mailbox > a").Count; i++)
{
driver.FindElementByLinkText(links[i]).Click();
}
I have a report that renders perfectly fine when I am populating it with data. I have complex charts, tables and a lot of data (around 20,000 memory objects). My report rendered perfectly fine untill I added a for loop for some data calculation. The for loop is as follows:
public void InsertLineBreaks(List<LineChart> inputList, int sampleInterval)
{
List<LineChart> breaklinesList = new List<LineChart> { };
for (int i = 1; i <= inputList.Count; i++)
{
if ((inputList[i].X - inputList[i - 1].X).TotalMinutes > sampleInterval)
{
LineChart breakline = inputList[i];
breakline.BreakLine = 1;
breaklinesList.Add(breakline);
}
inputList.AddRange(breaklinesList);
}
This code basically checks if every data has same interval otherwise adds a breakline. When I add this code, my reportviewer directly shows a blank page without any errors or report controls (next, print, export, etc. buttons). However, if I comment this code out, the report generates just fine without any issues.
I tried debugging the code and put a breakpoint on the data sources. I was surprised to see that the reportviewer still runs and shows a blank page despite the breakpoint. So obviously, the data is not binded and that is why the report viewer is blank.
I suspect reportviewer exceeds the memory allotted to it hence skips my code and data binding and prints blank page. Can anyone help?
The problem was not with the memory of report builder but with my code. i changed the code to the following and it worked:
public void InsertLineBreaks(List<LineChart> inputList, int sampleInterval)
{
List<LineChart> breaklinesList = new List<LineChart> { };
for (int i = 1; i <= inputList.Count; i++)
{
if ((inputList[i].X - inputList[i - 1].X).TotalMinutes > sampleInterval)
{
LineChart breakline = inputList[i];
breakline.BreakLine = 1;
breaklinesList.Add(breakline);
}
}
inputList.AddRange(breaklinesList);
}
I'm simply trying to place the value from the selected cells of a datagridview into an array. I've tried it several different ways, and this one feels the most efficient, but none of the ways I've gone about have been successful. I've done plenty of searching for this fix, several results were on this site, but still no dice. Here's what I have:
Creating the array further up in the code:
public string[] addedMovies;
On clicking the Confirm button, get the number of selected cells and store that as selectedCellCount. Then, add the selected cells one at a time into the array using a while loop. Info on results below the following code:
private void btnConfirm_Click(object sender, EventArgs e)
{
int selectedCellCount = dgvFiles.GetCellCount(DataGridViewElementStates.Selected);
int i = 0;
while (i < selectedCellCount)
{
//MessageBox.Show("" + dgvFiles.SelectedRows[i].Cells[0].Value);
addedMovies[i] = dgvFiles.SelectedRows[i].Cells[0].ToString();
//addedMovies[i] = dgvFiles.SelectedRows[i].Cells[0].Value.ToString();
MessageBox.Show("" + addedMovies[i]);
i++;
}
i = 0;
}
I am successful at showing them one at a time with the commented message box line of code, and I've also tried the commented line to add the values to the array as well with no luck. However, when I select a cell or cells and click Confirm, I am greeted with: "NullReferenceException was unhandled. Object reference not set to an instance of an object." I fail to understand where there's an issue in the coding, and why I'm unable to save the values into the array.
can you try to define array like this
public string[] addedMovies = new string[100];