i have a table array dynamically generated from a data query and stored in a session variable. Now i wanna add a textbox to limit how many rows at a time i will display. To test this, i wrote two button methods, one will set some rows to be visible = false, and the second button method will set the same rows back to visible = true.
protected void limit_btn_Click(object sender, EventArgs e)
{
for (int i = 0; i < traceTables.Length; i++)
for (int j = 2; j < traceTables[i].Rows.Count; j++)
traceTables[i].Rows[j].Visible = false;
Session["Tables"] = traceTables;
table_C();
}//end limit_btn_Click()
protected void obo_btn_Click(object sender, EventArgs e)
{
for (int i = 0; i < traceTables.Length; i++)
for (int j = 2; j < traceTables[i].Rows.Count; j++)
traceTables[i].Rows[j].Visible = true;
Session["Tables"] = traceTables;
table_C();
}//end obo_btn_Click()
protected void table_C()
{
String changeTo = log_locations.SelectedValue;
for (int i = 0; i < sshLoc.Length; i++)
{
if (sshLoc[i].CompareTo(changeTo) == 0)
{
table_panel.ContentTemplateContainer.Controls.Remove(traceTables[currentTable]);
System.Diagnostics.Debug.WriteLine("Removing " + sshLoc[currentTable]);
table_panel.ContentTemplateContainer.Controls.Add(traceTables[i]);
System.Diagnostics.Debug.WriteLine("Adding " + sshLoc[i]);
currentTable = i;
Session["CurrentTable"] = currentTable;
break;
}//end if
}//end for
}//end table_C()
table_C() basically removes and adds the table from the panel - i use it when i want to switch between tables from a dropdown list (which works) and in this case it simply removes and adds the same table from the panel content container.
The problem is that setting the rows to be not visible works fine. Setting the rows back to visible never does, and i'm not sure why
Try using display:none and display:visible rather than .visible in ASP
traceTables[i].Rows[j].Add("style","display:none");
Visible removes it completely from the HTML, so you can only show it again by recreating the page.
You need to store data in a list rather than in a table.
When you set the rows to not visible they are being removed from the html table. That is why you cannot set them to visible again.
If you store the data in a seperate object and bind it to the list, you will be able to turn visibility on and off.
Related
If you add more than 282 XRTableRow dynamically into a XRTable, the XRTable and any subsequent contents will not show in the report.
Please note that it is always required to call the XRTable.BeginInit and XRTable.EndInit methods if you modify XRTable.Rows and XRTableRow.Cells collections at runtime.
As for the height of a table, explicitly specify it only if cells' content is not expected to stretch the cells (e.g. this may happen when their CanGrow property is enabled).
public XRTable CreateXRTable() {
int cellsInRow = 3;
int rowsCount = 3;
float rowHeight = 25f;
XRTable table = new XRTable();
table.Borders = DevExpress.XtraPrinting.BorderSide.All;
table.BeginInit();
for (int i = 0; i < rowsCount; i++) {
XRTableRow row = new XRTableRow();
row.HeightF = rowHeight;
for (int j = 0; j < cellsInRow; j++) {
XRTableCell cell = new XRTableCell();
row.Cells.Add(cell);
}
table.Rows.Add(row);
}
table.EndInit();
return table;
}
then add this table to report specific band i,m adding this to Detail band
this.Detail.Controls.Add(CreateXRTable());
I'm pretty new to ASP.NET. Please forgive me for my knowledge :) Assuming I want to create 4 imagebuttons. If I click on any imagebutton, it will move me to another page with different STT (<- just a name).
Here's my code:
for (int i= 0; i< 4; i++)
{
ImageButton image = new ImageButton();
image.Click += (s, args) =>
{
Response.Redirect("~/Showroom.aspx?STT=" + (i));
};
//other things to do
}
Now the problem is that when I click on any imagebutton. I'll be redirected to Showroom.aspx with STT = 4 (which is i after the loop). How can I be redirected to the page with desired STT.
EDIT:
Just to clarify. What I want is Clicking on imagebutton 1 will move me to Showroom.aspx with STT = 0. Imagebutton 2 will move me to the page with STT=1 and so on.
Problem
"~/Showroom.aspx?STT=" + (i) means it captures the variable i rather than its value at the time of delegates creation.
Solution
Create url outside of delegate.
for (int i = 0; i < 3; i++)
{
string url = string.Format("~/Showroom.aspx?STT={0}", i);
var image = new ImageButton();
image.Click += (s, args) => Response.Redirect(url);
}
You need to copy i to a local variable. Or as the other Answer suggests, build your URL before its used in your lambda expression.
int x = i;
image.Click += (s, args) =>
{
Response.Redirect("~/Showroom.aspx?STT=" + (x));
};
I am making a shopping cart type of thing using grid view user will keep adding item in it after doing it so user will click save i want to get values from all columns of grid view each row at a time and save it to database.
here is the code for grid view load
protected void add_Click(object sender, EventArgs e)
{
product.Item = Item_Drop.SelectedItem.Text;
product.Quantity = quantity_box.Text;
int qun =Convert.ToInt32(quantity_box.Text);
int unitP= Convert.ToInt32(unitPrice_box.Text);
product.item_Toal = (qun*unitP).ToString();
list.Add(product);
temp_gridView.DataSource = list;
temp_gridView.DataBind();
}
And here is what i am trying to get values
public void Values_from_grid()
{
foreach(temp_gridView row in temp_gridView.Rows)
{
for(int i = 0; i < temp_gridView.Columns.Count, i++)
{
String header = temp_gridView.Columns[i].HeaderText;
String cellText = row.Cells[i].Text;
}
}
}
i am not getting any values in "header" or "cellText" . .. .
Use this code to get header row value .
GridViewName.HeaderRow.Cells[0].Text;
Found Answer no need to use
GridView.Rows.Count
just use a simple int to iterate
int i = 0;
foreach(GridViewRow row in temp_gridView.Rows)
{
box.Item_id = temp_gridView.Rows[i].Cells[0].Text;
box.Quantity = temp_gridView.Rows[i].Cells[1].Text;
box.Total = temp_gridView.Rows[i].Cells[2].Text;
i++;
}
I have a TreeView in my code (Tree1) and i am going to add nodes in depth , using my CreatTree() method. In Debug i understood that this line
(Tree1.Nodes[i].ChildNodes.Add(new TreeNode(i.ToString()))) does not lead to adding a node to Tree so the error in the loop is:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Can anybody tell me how can i add a Child to a certain Node?
<asp:TreeView ID="Tree1" runat="server" >
</asp:TreeView>
The code behind is:
protected void CreateTree( )
{
Tree1.Nodes.Add(new TreeNode("0"));
for (int i = 0; i < 4; i++)
Tree1.Nodes[i].ChildNodes.Add(new TreeNode(i.ToString()));;
}
can you tried with below code because at patent level you have added only 1 record and you tried to add new child node at four different parent node.
protected void CreateTree( )
{
Tree1.Nodes.Add(new TreeNode("0"));
for (int i = 0; i < 4; i++)
Tree1.Nodes[0].ChildNodes.Add(new TreeNode(i.ToString()));;
}
This should do what I think you're looking for:
protected void CreateTree()
{
Tree1.Nodes.Add(new TreeNode("0"));
TreeNode currentNode = Tree1.Nodes[0];
for (int i = 0; i < 4; i++)
{
currentNode.ChildNodes.Add(new TreeNode(i.ToString()));
currentNode = currentNode.ChildNodes[0];
}
}
You'll end up with 5 nodes, one under each other.
On !PostBack dynamic templates are created based on the number of rows needed for check boxes. The control id's are chkbox_id. I am unable to retrieve the dynamic check boxes via the following code and NullReferenceException is always thrown.
The code before loops through the gridview rows, then datatable dt references the possible number of dynamic columns.
for (int i = 0; i < dt.Rows.Count; i++)
{
string id = dt.Rows[i]["id"].ToString();
CheckBox cb = (CheckBox)row.FindControl("ckbox_" + id);
if (cb.Checked)
{ // do things }
}
Checkboxes defined here within page load:
if (!Page.IsPostBack)
{
foreach (DataRow dRow in dt.Rows)
{
TemplateField ckhColumn = new TemplateField();
ckhColumn.HeaderTemplate = new GridViewTemplate(ListItemType.Header, dRow["name"].ToString());
ckhColumn.ItemTemplate = new GridViewTemplate(ListItemType.Item, "ckbox_" + dRow["id"].ToString());
gvProductPriceList.Columns.Add(ckhColumn);
}
}
Let me know if I need to clarify anything else.
I'm not positive on this, and I don't have a minute to try it, but it might work if you do a row.Parent.FindControl(...). Also, if you use the as operator instead of a direct cast, you won't have the null reference exception (i.e. you can check for it):
CheckBox cb = row.Parent.FindControl("ckbox_" + id) as CheckBox;
if (cb != null)
{
// ...
}