I have a telerik radgrid in my .aspx page name rgLowRise, and I have an ObjectDataSource as the DataSource set like rgLowRise.DataSourceID = odsLowRise. This works fine, but I want it not to show any records at first load, how can I do that? And I have to use DataSourceID and not DataSource due to some reasons.
Thanks
You can remove the DataSourceID from the markup or your code behind (Page_Load) and set at a later stage, e.g. Button_Click or some other event
protected void Button_Click(object sender, EventArgs e)
{
rgLowRise.DataSourceID = odsLowRise; //until you click this button, the grid would display nothing
}
Related
Now I am trying to use a button on the parent page to a usercontrol.
There is a checkboxlist on the usercontrol, and its datasource is read from database
the checkboxlist didn't load correctly. it is like:
OnlineRenewa_draft1.tbl_LanguageChoices OnlineRenewa_draft1.tbl_LanguageChoices OnlineRenewa_draft1.tbl_LanguageChoices
OnlineRenewa_draft1.tbl_LanguageChoices OnlineRenewa_draft1.tbl_LanguageChoices OnlineRenewa_draft1.tbl_LanguageChoices
is it about postback issue?
Any idea?
thanks
protected void Page_Load(object sender, EventArgs e)
{
//if (!IsPostBack) {
List<tbl_LanguageChoices> LanguageList = ((List<tbl_LanguageChoices>)Cache["LanguageChoise"]);
otherlanguage.DataSource = LanguageList;
otherlanguage.DataBind();
otherlanguage.DataTextField = "Languages";
otherlanguage.DataValueField = "GUID";
}
You're first databinding the checkboxlist's to the DataSource and then setting DateValueField and DataValueField. DataBind should be the last step.
otherlanguage.DataSource = LanguageList;
otherlanguage.DataTextField = "Languages";
otherlanguage.DataValueField = "GUID";
otherlanguage.DataBind();
Have you set the DisplayMember property of your CheckBoxList? You need to set it to the column/property of the object you have set as the datasource. Or as MSDN puts it:
Gets or sets a string that specifies a property of the objects
contained in the list box whose contents you want to display.
Although, questions somehow similar to this have been asked for a number of times, but the question is still unsolved. Here is the question:
I have a GridView which is contained in a tab container AJAX control which itself is inside an UpdatePanel. Gridview works excellent and its corresponding methods are fired accurately, but when I enable paging(e.g.) after I click on page 2, the GridView hides itself. here is my PageIndexChanging() method:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
UpdatePanel2.Update();
}
Why paging causes GridView to stop working correctly? What can I do?
The solution is that you should refill the dataset which is used to populate the gridview, each time your page index is changed. By this way, you could ensure that in each seperate postback which has been triggered by the gridview page number, results will be populated.
I just tried that above code. I had same issue and now it is working just fine.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
// UpdatePanel2.Update(); <-- Remove this line from your code.
}
I have GridView inside update panel. Did you write your event PageIndexChanging in your .aspx file also?
Hope this helps.
Further research:
http://msdn.microsoft.com/en-us/library/cc295545.aspx
Controls that are not compatible with UpdatePanel controls
The following ASP.NET controls are not compatible with partial-page updates, and are therefore not designed to work inside an UpdatePanel control:
GridView and DetailsView controls when their EnableSortingAndPagingCallbacks property is set to true. The default is false.
I had the same issue , changing the updatepanel property UpdateMode="Conditional" to UpdateMode="Always" and setting the property ChildrenAsTriggers="true" solved the problem for me.
To do it, you have to re set the datasource in the page index change event. The performance will be lower but that's the way you can make it works.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.DataSource = ;//Set again the datasource
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
UpdatePanel2.Update();
}
this error apear when I try to cancel row in grid view
The GridView 'GridView1' fired event RowCancelingEdit which wasn't handled
In the mark up, add row cancelling edit event for the gridview
RowCancelingEdit="GridView1_RowCancelingEdit"
In the code behind add,
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//switch back to default mode
GridView1.EditIndex = -1;
//Bind the grid
Gridview1.Datasource=yourDatasource;
GridView1.DataBind();
}
If this is ASP.NET then you may have specified the name of the handler in the ASP.Net page and not implmented it in the Code Behind page.
Can you post the code where it is defined?
You will have
<asp:GridView ID="GridView1" runat="server" RowCancelingEdit="MyFunction">
Just remove the RowCancelingEdit section
Try checkng the value of "EditItemIndex" in page prerender, see if it get chaged after the first postback.
With Gridview after setting the EditItemIndex, you have to do a rebind usually by just calling your GridView1.DataBind()
I have a PlaceHolder control inside of a ListView that I am using to render controls from my code behind. The code below adds the controls:
TextBox tb = new TextBox();
tb.Text = quest.Value;
tb.ID = quest.ShortName.Replace(" ", "");
((PlaceHolder)e.Item.FindControl("ph_QuestionInput")).Controls.Add(tb);
I am using the following code to retrieve the values that have been entered into the TextBox:
foreach (ListViewDataItem di in lv_Questions.Items)
{
int QuestionId = Convert.ToInt32(((HiddenField)di.FindControl("hf_QuestionId")).Value);
Question quest = dc.Questions.Single(q => q.QuestionId == QuestionId);
TextBox tb = ((TextBox)di.FindControl(quest.ShortName.Replace(" ","")));
//tb is always null!
}
But it never finds the control. I've looked at the source code for the page and the control i want has the id:
ctl00_cphContentMiddle_lv_Questions_ctrl0_Numberofacres
For some reason when I look at the controls in the ListViewDataItem it has the ClientID:
ctl00_cphContentMiddle_lv_Questions_ctrl0_ctl00
Why would it be changing Numberofacres to ctl00? Is there any way to work around this?
UPDATE:
Just to clarify, I am databinding my ListView in the Page_Init event. I then create the controls in the ItemBound event for my ListView. But based on what #Womp and MSDN are saying the controls won't actually be created until after the Load event (which is after the Page_Init event) and therefore are not in ViewState? Does this sound correct?
If so am I just SOL when it comes to retrieving the values in my dynamic controls from my OnClick event?
UPDATE 2:
So i changed the code i had in my Page_Init event from:
protected void Page_Init(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
//databind lv_Questions
}
}
to:
protected void Page_Init(object sender, EventArgs e)
{
//databind lv_Questions
}
And it fixed my problem. Still a little confused as to why I want to databind regardless of whether it's a postback or not but the issue is resolved.
It looks like you're adding your textbox to a Placeholder control... but then you're searching a ListViewDataItem container for it later.
Seems to me that you need to search for the Placeholder first, and then search it for the textbox.
1) I noticed that if we don’t bind GridView to object data source control, then when user puts GridView into edit mode, we have to handle GridView.RowEditing event (else we get an exception ) and in this event put GridView’s row into editing mode. Is there a reason why GridView doesn’t automatically put a row into edit mode?
2) When we manually bind GridView to one of DataSet’s tables and user puts a row into edit mode, row’s columns will replace fields with text boxes. But for some reason these text boxes don’t display current field values, but instead they don’t display any text at all. What am I doing wrong?
3) I’ve also handled gridView.RowUpdated event, so I could put row back into non-edit mode, but to no effect. I even tried by pressing Edit button of some other row, but row still wouldn’t go out of edit mode. Any ideas what I’m doing wrong?
protected void gvwEmployees_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
e.KeepInEditMode = false;
}
Thanx
When not using a DataSource control with a GridView or other data-bound control which hide the complexity of the manual data-binding you must manually handle RowEditing, RowUpdating, and RowDeleting etc. With the built in data model and automatic binding the GridView handles these events for you.
You haven't posted your RowEditing code, but i suspect that you are not setting the GridViews EditIndex to the NewEditIndex and are not rebinding, this is probably why you are not seeing current data.
protected void gvwEmployees_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditINdex;
BindData();
}
The same is true for your RowUpdating event. You will have to manually update your data, then set the EditIndex to -1, this will put your GridView back into ReadOnly mode. Keep in mind that e.OldValues, e.NewValues and e.Keys properties of the GridViewUpdateEventArgs are not populated when binding manually. This mean you'll have to take care of the update yourself by using e.RowIndex which is the index of the edited row.
protected void gvwEmployees_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridView.EditIndex = -1;
BindData();
}