I has a Gridview called Gridview1 which is binded to a datasource.
and I have a ItemTemplate at Column 5 within it contain a
- Linkbutton called search
- Label called lbl_password , visible press to true
- Label called txt_password , visible set to false
code in done in asp.net webForm , .aspx
when link button pressed this function will get the ID at cell 1 in the row tat button clicked
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
string fieldID = grdrow.Cells[1].Text;
Now i want to know how can I make the txt and lbl become visible when the button pressed
I am assuming you mean when link button pressed you want to make the text and label from the same row to be visible.For that purpose you can just use the findcontrol method on gridview row to find the control you need.
If that's what you want then in link button click event you can do as follow,
protected void lnkButton_Click(object sender, EventArgs e)
{
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
((TextBox)grdrow.FindControl("yourtextboxID")).Visible = true;
((Label)grdrow.FindControl("yourLabelID")).Visible = true;
}
Here is more info on findcontrol.
Related
My Question is about to disable and Enable focused cell of Grid View and change disable cell to color on Key press
but i don't have any idea how to do that I Have done specific row Enabled False using row state helper class But now i want to disable cell How can i do that?
You can use GridView's ShowingEditor event:
private void gridViewTest_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
{
GridView gridView = sender as GridView;
if(gridView.FocusedColumn.FieldName == "Product Name") // && <PUT OTHER CONDITIONS HERE>
e.Cancel = true;
}
Simple question which my searches seem to be coming up blank on.
I have a GridView that is AutoGeneratingColumns=True
This generates a column "MyColumn". I would like to make this columns value a clickable LinkButton that fires the RowCommand event of the GridView with a specific CommandNmae and the cells value as the CommandArgument.
I'm trying to do this without using a custom ItemTemplate, I know how to do that. I'm hoping i can pragmatically modify a auto generated column in the GridView as described.
Tia
This can be done in the OnRowDataBound event of the GridView.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//check if the current row is a datarow
if (e.Row.RowType == DataControlRowType.DataRow)
{
///create a new linkbutton
LinkButton button = new LinkButton();
button.Text = "LinkButton";
button.CommandArgument = "MyArgs";
//assign a command to the button
button.Command += Button_Command;
//add the button to cell x
e.Row.Cells[3].Controls.Add(button);
}
}
Because you are adding control dynamically, the binding of the GridView should NOT be wrapped inside an IsPostBack check. Something you would do normally.
I am creating the dynamic grid and adding textbox and label in row dynamically on some button click and bind some data from the database to textbox and label.I want to change the label text color and text box read only for condition depend on database.i have used onRowDataBound event of gridview but not getting any value in the textbox and label for a row. Can anyone helps me to solve this issue? Thanks
protected void grdMasterData_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label status = e.Row.FindControl("lblProduct") as Label;
if (status.Text == "LY Actuals")
{
e.Row.Cells[0].CssClass = "lblProductColor";
// lbtAction.Visible = false;
}
}
}
In RowDataBound three row types provided by grid, you are using only DataRow, try to get your values from empty row and footer row because first record will not come in DataRow.
I have a button, when clicked, a modalpopup with gridview inside it. as below;
protected void grdDetails_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = grdDetails.SelectedRow;
//Note: Value of that row's cell must display in A text box (txtBox) on main page
txtBox.Text = row.Cells[2].Text;
ChargeFilterModalDialogExtender.Hide();
}
After the extender is hide, the value of the cell not displaying in the text box. Am I doing something wrong?
Where you have the textbox?
Whether you are using UpdatePanel?, if so define the needed asynchronous postback triggers.
I've got one long GridView control on ma website. It allows row selection. The problem is, when I scroll down this GridView and select some of the bottom rows the selection occurs, but whole GridView is scrolling back to top.
I refer this link for resolving my problem but not able to find any property into GridView control. I also search on msdn Link .
Please guide me where is this property and how can resolve my issue.Base on below checkbox event I select the row. After check the checkbox enable to delete and edit button.
protected void ChkChanged_Click(object sender, EventArgs e)
{
int count = 0;
foreach (GridViewRow gr in grdProducts.Rows)
{
CheckBox chkGrd = ((CheckBox)gr.FindControl("CheckBox2"));
ImageButton editbutton = gr.FindControl("btnEdit") as ImageButton;
ImageButton deleteButton = gr.FindControl("btnDeleted") as ImageButton;
if (chkGrd.Checked)
{
count++;
editbutton.Visible = true;
deleteButton.Visible = true;
if (count > 1)
break;
}
else
{
editbutton.Visible = false;
deleteButton.Visible = false;
}
}
if (count > 1)
{
foreach (GridViewRow gr in grdProducts.Rows)
{
CheckBox chkGrd = ((CheckBox)gr.FindControl("CheckBox2"));
ImageButton editbutton = gr.FindControl("btnEdit") as ImageButton;
ImageButton deleteButton = gr.FindControl("btnDeleted") as ImageButton;
if (chkGrd.Checked)
{
editbutton.Visible = false;
deleteButton.Visible = false;
}
}
DeleteAll.Enabled = true;
}
}
Can you give your 'row selection' code,is it posting back the entire page,If so, try to put the GridView in an UpdatePanel, so that the event is sent to the server without actually reloading the whole page.
Where are the scrollbars - to the page or to the grid-view? If possible, get rid of scrollbars to the grid-view and get scroll bars at the page level. In such case, you can use MaintainScrollPositionOnPostback which is a page property and it maintains page' scroll position on the post-back.
If your layout does not allow you to have scroll-bars at the page then I will suggest that you use a container div to the grid-view and have scroll-bars at the div level (instead of table i.e. grid-view) level. Now, you can have some JS code that can record the scroll position into the hidden field before page gets submitted and then same can use used after post-back to restore the position back. See this link where it uses such a trick : http://michaelsync.net/2006/06/30/maintain-scroll-position-of-div-using-javascript-aspnet-20
I found the answer .
In GridViewRow have Focus() method.
gr.Focus();
It's 95% set the position in your gridview selected Row.