C# Pager issue with dropdown - c#

I have create a ajax pages custom control with previous and next link and now when I am adding a drop down to the controls it is not working as desired..
I have used the code form http://www.flixon.com/Articles/Custom-ASPNET-Data-Pager-Control-22.aspx
When I am adding a drop down then on selected index change the previous and next button are getting disappeared. I believe this is due to I am binding the drop down in pre render event

Instead of binding drop down for paging in pre render event you can also bind it at the time of binding grid.
if (gridView.BottomPagerRow != null)
{
GridViewRow myGridViewRow = gridView.BottomPagerRow;
DropDownList ddCurrentPage = (DropDownList)myGridViewRow.Cells[0].FindControl("ddCurrentPage");
//To do to bind Drop down
}
and you can also explicitly call drop down selected index change event
Here is the code for pager template
<PagerTemplate>
<asp:Button runat="server" ID="imgPagePrevious" CssClass="Pagingbutton" Text="<"CommandArgument="Prev" CommandName="Page" OnCommand="imgPagePrevious_Command" />
<asp:DropDownList ID="ddCurrentPage" runat="server" CssClass="PagingDrop" AutoPostBack="True" OnSelectedIndexChanged="ddCurrentPage_SelectedIndexChanged">
</asp:DropDownList>
<asp:Button runat="server" ID="imgPageNext" CssClass="Pagingbutton" Text=">" CommandArgument="Next" CommandName="Page" OnCommand="imgPageNext_Command"/>
</PagerTemplate>
Try this.

Related

DataBinder.Eval Issue

I have a some controls inside an EditItemTemplate within a RadListView control:
<telerik:RadComboBox ID="cbCategoryTypeTueET" runat="server" Skin="Office2010Black"
SelectedValue='<%# DataBinder.Eval(Container.DataItem, "CategoryTypeID") %>'
TabIndex="1" Width="100%" EmptyMessage="--Select Category Type--" DataSourceID="edsCatTypeTueET"
DataTextField="CategoryName" DataValueField="CategoryTypeID" AutoPostBack="True"
OnSelectedIndexChanged="cbCategoryTypeTueET_SelectedIndexChanged" AccessKey="t" AppendDataBoundItems="True">
</telerik:RadComboBox>
<asp:EntityDataSource ID="edsCatTypeTueET" runat="server" ConnectionString=""
DefaultContainerName="ATITimeEntry" EnableFlattening="False" EntitySetName="TimeTrackingCategoryTypes"
Select="it.[CategoryTypeID], it.[CategoryName]"
Where="it.deletedFlag = false AND it.activeFlag = true" >
</asp:EntityDataSource>
The Entity datasource does have a connection string - I am using a new code generation template - so this is not an issue.
My problem is I want the combobox to bind on edit. But if activeFlag is false or deletedFlag is true (or both) the Radlistview will not go into edit mode. Is there an elegant way to do this with markup or some elegant query?
My understandig is, you want to forbid edit on some conditions.
You have to subscripe the ItemDataBound Event from the RadListView. There you can cast DataItem to your object and check the condition (Get Data being bound to ListView).
Then you can access your controls and manipulate them (like hide them)...
Conditionaly disable command button

dynamically adding controls does not displayed inside panel in asp.net web form

I have a web form with a table where one row contains panel to add fileupload controls dynamically
the code is as below
<tr>
<td style="width:70%;display:block; overflow:visible;" >
<asp:Panel ID="ImagePanel" runat="server">
<uc1:AddNewImage runat="server" id="AddNewImage" /></asp:Panel>
<asp:Button ID="AddImage" OnClick="Unnamed_Click" Text="Add New Image" runat="server" CausesValidation="False" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="Please Enter Model Items" ForeColor="Red" ControlToValidate="TxtItems"></asp:RequiredFieldValidator>
</td>
</tr>
In button click event i am adding new usercontrol to ImagePanel using following code
Controls.AddNewImage Obj = (Controls.AddNewImage)LoadControl(#"~/Controls/AddNewImage.ascx");
this.ImagePanel.Controls.Add(Obj);
Problem is only two controls are displayed inside the panel, i need to allow upto five controls, but these controls are not displayed inside panel. What should i need to do to get displayed these controls inside the panel. do i need to set any css for Panel. Panel is inside a tag.
That's because dynamically added controls are cleared when page PostBack. Simply solution is to add <asp:HiddenField id="hidCount" runat="server" value="1"/> and update your click event like this:
int count = int.Parse(hidCount.Value)++;
hidCount.Value = count.ToString();
for(i=0;i< count;i++) {
Controls.AddNewImage Obj = (Controls.AddNewImage)LoadControl(#"~/Controls/AddNewImage.ascx");
this.ImagePanel.Controls.Add(Obj);
}
This will work perfectly.

How to use linkbutton in repeater using C# with ASP.NET 4.5

In asp.net I have a table in database containing questions,date of submission and answers.On page load only questions appear.now i want to use any link which on clicking show answers and date specified in table data, either in textbox or label and clicking again on that link answer disappear again like expand and shrink on click.
So what coding should i use for this in C#?
I believe you could handle the ItemCommand event of the Repeater.
Place a LinkButton control for the link that you want the user to click in the Repeater's item template. Set the CommandName property of this to something meaningful, like "ShowAnswers". Also, add a Label or TextBox control into the Repeater's item template, but set their Visible property to false within the aspx markup.
In the code-behind, within the ItemCommand event handler check if the value of e.CommandName equals your command ("ShowAnswers"). If so, then find the Label or TextBox controls for the answers and date within that Repeater item (accessed via e.Item). When you find them, set their Visible property to true.
Note: you could take a different approach using AJAX to provide a more seamless experience for the user, but this way is probably simpler to implement initially.
I think the implementation would look something like this. Disclaimer: I haven't tested this code.
Code-Behind:
void Repeater_ItemCommand(Object Sender, RepeaterCommandEventArgs e)
{
if (e.CommandName == "ShowAnswers")
{
Control control;
control = e.Item.FindControl("Answers");
if (control != null)
control.Visible = true;
control = e.Item.FindControl("Date");
if (control != null)
control.Visible = true;
}
}
ASPX Markup:
<asp:Repeater id="Repeater" runat="server" OnItemCommand="Repeater_ItemCommand">
<ItemTemplate>
<asp:LinkButton id="ShowAnswers" runat="server" CommandName="ShowAnswers" />
<asp:Label id="Answers" runat="server" Text='<%# Eval("Answers") %>' Visible="false" />
<asp:Label id="Date" runat="server" Text='<%# Eval("Date") %>' Visible="false" />
</ItemTemplate>
</asp:Repeater>

How do I add an UpdatePanel and its trigger programmatically?

I'm adding a variable number of update panels in Page_Init.
I already have a script manager in my master page.
The problem is that when I try to add a trigger like:
AsyncPostBackTrigger trig2 = new AsyncPostBackTrigger();
trig2.ControlID = ddl22.UniqueID;
trig2.EventName = "SelectedIndexChanged";
up2.Triggers.Add(trig2);
where ddl22 is a DropDownList, the event never seems to trigger the UpdatePanel.
In the UpdatePanel I have another DropDownList the data of which i want to change when the trigger happens.
The funny thing is that in the master page I have a timer. This timer is only supposed to trigger the UpdatePanel in the master but it seems to trigger all of my update panels. However, even when it triggers the update panel in the child page, the second DropDownList does not change its data.
The data is databound to the DropDownList in the UpdatePanel in page_init. It is bound to an objectdatasource which uses the selected item in the first DropDownList as a parameter to determine what data it should bind.
Did you set AutoPostBack="True" for your drop down list? I suspect this is the issue.
Also set your update panel mode to conditional-UpdateMode="Conditional" so that i does not affect other update panels.
Try this,
In Source Code,
<asp:UpdatePanel ID="up2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl1_SelectedIndexChanged"></asp:DropDownList>
<asp:DropDownList ID="ddl2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl2_SelectedIndexChanged"></asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="ddl2" />
</Triggers>
</asp:UpdatePanel>
You can manually call the UpdatePanel to refresh without specifying a trigger on a postBack event. Firstly, set the UpdateMode property to 'Conditional', then you can just call an update on your updatepanel from code behind like
MyUpdatePanel.Update();

Can a CollapsiblePanelExtender expand from code behind?

I have added a checkbox to the rows of a gridview that when clicked will expand a panel in the row. My gridview needs to use paging, so I am saving in a session variable the state of the current page before the page change. When the user clicks back to a page I am repopulating the checkboxes, but this does not expand the panels. Is there away to expand the panels from the code behind?
<asp:CheckBox runat="server" Text="Order Updated Records" ID="cbUR" Visible='<%# !DBNull.Value.Equals(Eval("AnyBox"))%>' />
<asp:CollapsiblePanelExtender ID="cInst" runat="server" TargetControlID="inst" Collapsed="true" AutoExpand="true" AutoCollapse="false" ExpandControlID="cbUR" CollapseControlID="cbUR" />
<asp:Panel ID="Inst" runat="server">
<asp:TextBox runat="server" ID="txtInst" TextMode="MultiLine" Width="200" />
</asp:panel>
I tried adding the panel, textbox and panel extender from the code, but could not get it to work. I read on a different post that the whole gridview would need to load from the code for this to work.
I would love to use something like
<asp:CollapsiblePanelExtender ID="cInst" runat="server" TargetControlID="inst" Collapsed='<%#!Convert.ToBoolean(rowItems[index].ToString()) %>' />
Would it be better not use the CollapsiblePanelExtender and find a different way to show the panels?
You could try adding a public/protected method:
public bool IsCollapsed(object rowId) {
//get row by ID here and return true if collapsed
return ....
}
that would return a value for a row that needs to be expanded or collapsed.
and use it like:
Collapsed='<%# IsCollapsed(Eval("RowId")) %>'
where RowId is a property that represents the ID of the item.

Categories

Resources