I have a listview and DataPager control. Now when I click a page number on the DataPager, the
ListView1_PagePropertiesChanging(object
sender,
PagePropertiesChangingEventArgs e)
event is fired. Now, I would like to identify which page number of the DataPager was clicked. For example, if Page 3 was clicked, then I would like to get the value 3. How can I do this?
Thanks in advance.
you can try a code like this.
protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
int pageindex = e.StartRowIndex / e.MaximumRows;
}
The PagePropertiesChangingEventArgs as members that have some of the information you might need
Related
Im trying to do a rather simple practice project and i got stuck for a while now.
I have 3 dropdownlists
and 3 views.
I want to do:
check if the current dropdownlist has chosen a value then that dropdown has a value, hide that view and show the next view.
my problem:
I have one method for all 3 of my dropdownlists that gets called when a change occurs.
I need to check which one of these dropdownlists triggerd the change so that i know which dropdownlist value i need to check(if it is empty or not) and depending on the value i show/hide views.
If more info is needed just ask and Thanks!
On the function you probably have something like
protected void OnChangedEvent(object sender, EventArgs e) {
// code here
}
sender contains the dropdown list that fired the event. So:
protected void OnChangedEvent(object sender, EventArgs e) {
var ddl = (DropDownList)sender;
}
and ddl will be the dropdown list.
What I am trying to do is to access the value from the TextBox1 to display back on the screen.
I tried to access it from the Page_Load() and the OnItemDataBound and they both failed.
It seem like the code is able to access the control but it return nothing back.
protected void Page_Load(object sender, EventArgs e)
{
Literal Literal1 = (Literal)Repeater1.Controls[Repeater1.Controls.Count - 1].FindControl("Literal1");
Response.Write(Literal1.Text);
//this techique is not working for the line below
TextBox TextBox1 = (TextBox)Repeater1.Controls[Repeater1.Controls.Count - 1].FindControl("TextBox1");
Response.Write(TextBox1.Text);
}
public void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//this techique is not working
if (e.Item.ItemType == ListItemType.Footer)
{
TextBox TextBox1 = (TextBox)e.Item.FindControl("TextBox1");
Response.Write(TextBox1.Text);
}
}
I'm not sure what you mean by "they both failed" but if the Text property of the Textbox is empty i might be because you are rebinding your repeater on each post back. Try wrapping your repeater .DataBind() with a !IsPostBack condition.
I have to use "Literal" as an alternate solution by passing the html Textbox problem. I do not like this solution but i guess i have to use it.
i have a webusercontrol in the edittemplate of the datalist. in the code behind, in the itemCommand, when i try to find it using findcontrol, i get null object.
what is it that i am doing wrong?
WebUserControl cntrl = (WebUserControl)e.Item.FindControl("myControl");
or i also tried the below, in the EditCommand event, because i have kept the usercontrol inside the EditTemplate of the DataList:
WebUserControl cntrl = (WebUserControl)DataList1.FindControl("myControl");
I think you're probably doing something like this :
protected void gridView_rowDataBound(Object sender, GridViewRowEventArgs e)
{
WebUserControl cntrl = (WebUserControl)e.Item.FindControl("myControl");
}
Keep in mind that you'd be looking at every single row - including the header and footer rows.
I think you need this :
protected void gridView_rowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow){
WebUserControl cntrl = (WebUserControl)e.Item.FindControl("myControl");
}
}
Actually never mind, i moved the control to the headertemplate and looking at its controls collection, i am able to find the control using FindControl. Not sure why its not finding if i place it in the edititemtemplate. but thanks guys appreciate your help.
I have code like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Do something
}
}
When I click on paging in datapager, first the IsPostBack condition is skipped since it is a postback and then control moves to listItems_PagePropertiesChanging() event.
After executing this event, the control goes to page_Load again and gets inside the if(!IsPostBack) condition.
This is happening only in Mozilla 3.0.14, but not in IE 7.0.
Anyone please give me a solution ASAP.
Thanks in advance
I try to have custom controls in a DevExpress grids detail row. When ever a row is expanded I would like to load data into those custom controls based on the Masters Key.
I am using the detailrow expended method.
protected void grid_DetailRowExpandedChanged(object sender, ASPxGridViewDetailRowEventArgs e)
if (e.Expanded)
{
int id = Convert.ToInt32(grd.GetRowValues(e.VisibleIndex, "ID"));
...
}
The problem is I don't know how to access the custom controls in the expended detail row. I don't see any Row or Items properties on the grid, which would have been with a FindControl().
Any one got a clue on how to get the detail row or even a row object?
Thanks!
Try this:
protected void grid_DetailRowExpandedChanged(object sender, ASPxGridViewDetailRowEventArgs e)
if (e.Expanded)
{
YourControlType yourcontrol = (YourControlType)grid.FindDetailRowTemplateControl(e.VisibleIndex, "YourControlName")
}