I have buttons in one Column called Type. When the user clicks on the button it should be disabled. This works fine in the first page but it doesnt on the second,third,fourth pages.
I have 10 rows in my page and e.CommandArgument gets the row number.
I believe the buttons are populated in the gridview from 0 to 9 and e.CommandArgument is 1-10. Thats why I have (e.CommandArgument) - 1 and it works find in the first page.
The things that in the second page the next buttons are again 0-9 but my e.CommandArgument is 11-20. Any ideas?
protected void GridViewType_RowCommand(object sender, GridViewCommandEventArgs e)
{
Button btnVote = (Button)GridViewType.Rows[Convert.ToInt32(e.CommandArgument) - 1].FindControl("btnVote");
btnV ote.Enabled = false;
}
try the following
protected void GridViewType_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)(e.CommandSource);
Button btnVote = (Button)row.FindControl("btnVote");
btnVote.Enabled = false;
}
kindly check this :
want to Find Control in gridview on RowCommand event
Related
Basically everytime I load or reload the page it treats every row in my gridview as if it has been clicked, thus calling the function in the codebehind related to it once for every row which at the time is set to 13 rows max. Thanks for any help.
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Attaching one onclick event for the entire row, so that it will
// fire SelectedIndexChanged, while we click anywhere on the row.
e.Row.Attributes["onclick"] =
ClientScript.GetPostBackClientHyperlink(this.GridView2, "Select$" + e.Row.RowIndex);
}
Console.WriteLine("");
}
I have grid view, and I have already disable the column auto width so I can manually set the size of column. after manually resize there's a extra blank column. and what I want is :
To disable the select row function when i click on outside of the column in Active, code and generate
Remove the extra column.
I already success fully hide the remaining column with this event or code
private void gridView1_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
{
if (e.Column == null)
{
e.Handled = true;
}
}
The thing is I still can click on the outside of the genre, and the row selection still follow where I click
Handle the GridView.MouseDown event in the following way:
private void gridView1_MouseDown(object sender, MouseEventArgs e) {
GridView view = (GridView)sender;
var hi = view.CalcHitInfo(e.Location);
Console.WriteLine(hi.HitTest);
if (hi.InRow && !hi.InRowCell)
DXMouseEventArgs.GetMouseArgs(e).Handled = true;
}
I have a one grid view, on row command event i am redirecting on another page with query string that contains a current page index of grid view.
On redirected page i have a back button, when i click on this button i want redirect previous page with specified page index
For example:
suppose i am on my page-1 and current page index of grid view is 15 and on row command event i am redirecting on page-2.when click "back button" it must be redirected to page-1 with page index of 15 of grid view.
My code is as below:
Code of page that contains grid view (Page-1)
if (e.CommandName.ToLower() == "application")
{
Response.Redirect("view-msme-em-1-with-print.aspx?pageIndex=" + i , false);
}
Code of page that contains Button(Page-2)
protected void iBtnBack_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("searchMSMEApplication.aspx?pageIndex=" + Request.QueryString["pageIndex"].ToString() );
}
Code on page load event that contains gird view(page-1)
protected void Page_Load(object sender, EventArgs e)
{
fillGridOnLoad(); // it fills a grid view with data
grvEm2Application.PageIndex = Convert.ToInt32(Request.QueryString["pageIndex"].ToString());
}
when i click a "Back" on "page-2" it is redirecting to page-1 but page index is not as i set. is any thing missing?
Try below code
protected void Page_Load(object sender, EventArgs e)
{
grvEm2Application.PageIndex = Convert.ToInt32(Request.QueryString["pageIndex"].ToString());
fillGridOnLoad(); // it fills a grid view with data
}
Just need to set PageIndex before data bind
On the last page if If i have 1 or 2 items the header and the pager stretch too much.. it all autosizes..
My gridview height is not set, But I set the row property to 30pixels..still doesnt prevent the autosizing..
I was searching for a solution over the net..and the closest solution that i found was that:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(this.GridView1.Rows.Count<this.GridView1.PageSize)//I need here to grab the last page..// do something like e.Row.... and last page.
{
foreach (GridViewRow tt in GridView1.Rows)
{ tt.Height = Unit.Pixel(30); }
}
}
It isnt correct.... what i need to happen, is when the user clicks the last page the height should be modified to to 30 pixels.
Any other ideas on how to prevent autosizing on the last page are welcome!!
To find out if you're on the last page of a paged grid and then change row heights, use the following (tested) code:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (GridView1.PageIndex == GridView1.PageCount - 1)
{
e.Row.Height = Unit.Pixel(30);
}
}
i have a alphabetic filter consist of 26 dynamically created link button on selecting any link button it is filtering the name of user's on the basis of alphabet and changing its color to orange to make it different from other linkbuttons it is working fine but if there are more number of user associated with a particular alphabet and on applying filter it is filtering the user on the basis of that alphabet and showing them in a list view on clicking the data pager next page or any other page number the link button changes its color to default color but i want to keep that highlighted until and unless other link button is selected
my code
protected void Page_Init(object sender, EventArgs e)
{
// Adding Dynamically linkbuttons for all alphabets(i.e. A-Z)
for (char asciiValue = 'A'; asciiValue <= 'Z'; asciiValue++)
{
LinkButton lbtnCharacter = new LinkButton();
lbtnCharacter.ID = "lbtnCharacter" + asciiValue;
divAlphabets.Controls.Add(lbtnCharacter);
// Setting the properties of dynamically created Linkbutton.
lbtnCharacter.Text = Convert.ToString(asciiValue);
lbtnCharacter.CssClass = "firstCharacter";
lbtnCharacter.ToolTip = "Show Tags starting with '" + Convert.ToString(asciiValue) + "'";
lbtnCharacter.CommandArgument = Convert.ToString(asciiValue);
lbtnCharacter.Command += new CommandEventHandler(lbtnCharacter_Command);
}
}
// For assigning default color to linkbutton text in page load
foreach (var ctrl in divAlphabets.Controls)
{
if (ctrl is LinkButton)
((LinkButton)ctrl).CssClass = "firstCharacter";
}
void lbtnCharacter_Command(object sender, CommandEventArgs e)
{
// Storing the values of pressed alphabet in viewstate.
ViewState["Selected_Character"] = e.CommandArgument;
LinkButton lbtnSelected = (LinkButton)divAlphabets.FindControl("lbtnCharacter" + e.CommandArgument);
lbtnSelected.CssClass = "firstCharacter highlighted";
txtTagFilter.Text = string.Empty;
BindTagList();
}
I hope I understood your question.
You are setting your Selected_Character item in the command handler and then setting the class of the button to highlight it. This only gets fired when the button is clicked, not when you move to the next page. Why not separate these two operations. Set the class of the link button on prerender if the Selected_Character matches. That way even when you page the link button will stay highlighted.
I would also set your selected character as a query string parameter, if someone copies and pastes a link to your page the button would not highlight and the correct data would not display.
Hope this helps.
Edit: Haven't tested the below but maybe it will get you started.
void lbtnCharacter_Command(object sender, CommandEventArgs e)
{
// redirect to self with tag as qs parameter
Response.Redirect(string.Format("{0}?tag={1}", Request.Url.GetLeftPart(UriPartial.Path), e.CommandArgument));
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (Request.QueryString["tag"] != null) {
LinkButton lbtnSelected = (LinkButton)divAlphabets.FindControl("lbtnCharacter" + Request.QueryString["tag"]);
lbtnSelected.CssClass = "firstCharacter highlighted";
}
}
N.B You will also need to change your BindTagList to use the query string also. I'm assuming you call this in the page load event.