I am using Telerik Grid. In that I have Check box for each row. Now I want that when I check more than one row and click on Asp button then it should update the selected rows. Now when I used:
protected void btnRead_Click(object sender, EventArgs e)
{
foreach (GridDataItem dataItem in invMenusAccessRadGrid.MasterTableView.Items)
{
}
}
I am not able to further implement inside the loop to get selected values.
Related
I have a GridView object on a C# WebForm page which displays table data and allows editing. I have made a Template Button column to execute the Update Command in my SQLDataSource Object.
The buttons are enabled by default, which caused errors when they were pressed without the Row being in Edit Mode. So I used the GridView1_DataBound() Event to disable the buttons for each row using FindControl on the appropriate column. This works fine.
protected void GridView1_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow gvrow in GridView1.Rows)
{
Button setButton = (Button)gvrow.Cells[7].FindControl("Button1");
setButton.Visible = False;
}
}
What I want to do is when a row is selected for editing, I enable only that row's button. I have been able to use FindControl to get a reference to the button (verified I have the reference doing Debug) But when I make changes to the button, it doesn't work.
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
DataBind();
int c = GridView1.Rows[e.NewEditIndex].Cells.Count - 1;
Button setButton = (Button) GridView1.Rows[e.NewEditIndex].Cells[c].FindControl("Button1");
// doesn't work!!
setButton.Visible = true;
}
In debug mode, I verified that I do have access to the button for the row and can see its properties, etc.
I have tried changing forecolor, text, etc. but nothing changes on the actual button; what do I need to do in order to change the button?
i have a gridview with devexpress my gridview contain a id ID="GriviewLV1" and i have a button in the row of the gridview to edit the record , in the event click of the button im trying give click in the button to edit but cannot get the property rows or something like that. im trying something like this but cannot do rows property because dont exist the rows property in grid view devexpress
button_Edit_click(object sender, EventArgs e)
{
foreach (GridViewRow row in GriviewLV1.Rows)
{
}
}
And for what exactly do you need row collection?
As far as I know, you can only manipulate with records (DataSource property object). Also it is possible to get selected row. Some my code examples with explanation:
private List<ImageSetMember> imageSets;
...
//assign collection as grid's DataSource.
//From now on any actions on imageSets object will be automatically reproduced
//as grid's row changes.
imageSetGridControl.DataSource = imageSets;
...
private void replaceButtonEdit_Click(object sender, System.EventArgs e)
{
//get focused row record's index at DataSource collection
int index = imageSetGridView.GetDataSourceRowIndex(imageSetGridView.FocusedRowHandle);
var selectedImage = imageSet[index].Image; //accessing to row's record
}
I have devexpress gridcontrol which looks like that:
I have click event on this red X button:
private void delete_button_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
}
How can get there row index where this button is ?
You cannot access rows on GridControl, since this is just a container for the views.
As I can see from your picture you're using GridView. When you press the delete button, focused row changes and you can access it via FocusedRowHandle.
private void delete_button_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
var gv = myGridControl.MainView as GridView;
var index = gv.FocusedRowHandle;
gv.DeleteRow(index);
}
You can use the GridView.FocusedRowHandle property:
view.DeleteRow(view.FocusedRowHandle);
Here is code that i used to access dropdownlist inside gridview on button click.I know its due to postback of page.But how to fix it.
protected void Button1_Click(object sender, EventArgs e)
{
GridViewRow row;
row = dgData.Rows[0];
DropDownList ddl= (DropDownList)(row.Cells[1].FindControl("ddlCol1"));
}
On page load i have called the method to bind gridview.
if (page.ispostback==false)
{
grdbind();
}
try with 0th cell if it is first
(row.Cells[0].FindControl("ddlCol1"))
So I have a ASP.NET DataGrid and in the SomeName_ItemBound I am trying to set the visibility of the row if certain conditions are met. However, I can't seem to find a way to acquire the row.
How do I select the current row in the:
SomeName_ItemBound(object sender, DataGridItemEventArgs e)
DataGrid is an old control you should use GridView, I guess you must be using GridView already.
You can get current row by e.Item inside your ItemBound event
like
protected void SomeName_ItemBound(Object sender, DataGridItemEventArgs e)
{
// Use the ItemDataBound event to customize the DataGrid control.
// The ItemDataBound event allows you to access the data before
// the item is displayed in the control. In this example, the
// ItemDataBound event is used to format the items in the
// CurrencyColumn in currency format.
if((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
// e.Item // is your current row
e.Item.Visible = false;
}
}