Can a CollapsiblePanelExtender expand from code behind? - c#

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.

Related

Getting event fired control cell of the grid view in Row command event

Can anybody please help me to get the cell index of the event fired control in row command of the grid view. I have one radio button control in side my grid view. If the user clicks on the radio button, i need to change the background color of the particular cell. Please help me to resolve this. My code is showing below.
<asp:TemplateField HeaderText="MD-R">
<ItemTemplate>
<asp:ImageButton ID="imgMDR" runat="server" ImageUrl="" ToolTip='<%# Eval("MDR") %>'
CommandName="MDR" CommandArgument='<%# ((GridViewRow) Container).RowIndex %>'
OnClientClick="javascript:return ConfirmReport(this);" />
</ItemTemplate>
</asp:TemplateField>
JQuery:
function ConfirmReport(obj) {
$("tr").removeClass("selectedrow");
$(obj).closest('tr').addClass("selectedrow");
}
CSS:
.selectedrow
{
background:green;
}
For code behind row selection, refer the below link.
Highlight gridview row in update panel without posting back

C# Pager issue with dropdown

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.

Gridview textbox on Page_load enable edit

using Visual.Web.Developer.2010.Express;
using SQL.Server.Management.Studio.2008.R2;
N00b here,
I've got the gridview to look the way I want it to (a textbox inside of the ItemTemplate). The Textbox's class has some client-sideJS that enables a save button (an asp:LinkButton set to look like a Jquery UI save icon) to become visible after the Textbox's .keypress event fires..
Now for my question..I've looked everywhere, but I can't get how to have gridview put the Sql server db content in that textbox on Page_load (one textbox + <br /> for each row). I'm only printing one collumn from the Sql server db into the Gridview.. Also, how would I bind the asp:LinkButton save button to gridview's save event? If there is a more effecient way to do this? If you have some insight for me, please give me your opinion/!
My .aspx code
<asp:TemplateField >
<ItemTemplate>
<asp:TextBox ID="TextBox1" class="hexen" runat="server" DataField="TbValue" SortExpression="TbValue">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:FluxConnectionString %>"
SelectCommand="SELECT [TbValue] FROM [InvestigateValues]">
</asp:SqlDataSource>
Thanks in advance!
Change your text box to
<asp:TextBox ID="TextBox1" class="hexen" runat="server" text='<%#Bind("TbValue")%>' />
This will enable two way databinding.
Here is an article to get you started: http://www.devx.com/DevX/Article/35058.
The grid view and SqlDataSource expose Insert, Update and Delete event/methods. These are on a row level, not grid level.
The way I would approach your problem would be to have an onclick event for your link button that iterates through the gridview, get the data from each text box and then perform the appropriate data base action in the code behind.

CollapsiblePanelExtender inside a ListView

I am trying to have a collapsible panel inside of a listview item. In the item template, I have a panel, and a collapsible panel extender. In order to set the attributes TargetControlID, CollapseControlID, etc., I need the ClientIDs that are generated after databinding for each of the listview items. Does anyone know how I can set those attributes client-side?
I've tried various things along the lines of the following:
<ItemTemplate>
<asp:Panel ID="ManagingPanel" runat="server">
</asp:Panel>
<asp:CollapsiblePanelExtender runat="server" TargetControlID='<%="ManagingPanel.ClientID" %>' />
</ItemTemplate>
SOLUTION - Turns out you do not need to use the ClientID. The Extender will recognize that its target is inside the same listview item.
<asp:CollapsiblePanelExtender runat="server" TargetControlID="ManagingPanel" />
I have create a custom user control that includes the CollapsiblePanelExtender and every other think that I like to show, a complex html struct, and then I have include this control in the repeater.
The repeater pass the data that I need to render my custom control, and then the custom control render its self in every line of the repeater, and all is working fine.
something like
<asp:Repeater ID="myRepeater" runat="server">
<ItemTemplate>
<uc1:MyCustonControl ID="lPro" runat="server" data="<%#PassData%>" />
</ItemTemplate>
</asp:Repeater>
Turns out you do not need to use the ClientID. The Extender will recognize that its target is inside the same listview item.
<asp:CollapsiblePanelExtender runat="server" TargetControlID="ManagingPanel" />

Asp:Label is not shown when visible is set to true?

I have a simple web form which has a couple list boxes and a search button. When the button is clicked, it returns a DataSet. If the dataset contains records, I set the asp:label which is initially set to false to true, but this is not happening. If the dataset has records and the visible property is set to true, the label still does not show up.
I have also tried putting the label and a couple other controls in an html table and setting a runat="server" attribute on the table and changing the visibility on that, but it does not show either.
Here is aspx code:
<table>
<tr>
<td>
<asp:Label ID="lblSortBy" runat="server" Text="Sort By:" Visible="false">
</asp:Label>
<asp:DropDownList
ID="ddlSortBy"
runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="ddlSortBy_SelectedIndexChanged">
<asp:ListItem Value="Gross">Gross</asp:ListItem>
<asp:ListItem Value="Population">Population</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
Here is simplified code behind when a button is clicked:
public void GetData()
{
DataView dv = GetReportData().DefaultView;
if(dv.ToTable().Rows.Count > 0)
{
lblSortBy.Visible = true;
}
else
{
lblSortBy.Visible = false;
}
}
I have a couple Update Panels around some ListBoxes and a GridView, but not the Label and Dropdown. Would this cause an issue?
I did a test, I set a label that was in an update panel to false if records were found and the label disappeared, so it is working if it is in an update panel.
If I'm not mistaken, your label should exist on an updatepanel, because as far as the static HTML page is concerned, the one and only time that your current label exists, it's set to be not visible. You would have to reload the whole page to make it visible again.
If the button is inside an UpdatePanel, then the Table, Label, etc. also have to be inside an UpdatePanel to get updated. Otherwise only the contents of the UpdatePanel get updated when clicking the button (this is what's called partial page-rendering).
So if the button is in an UpdatePanel, you have two possibilities to solve the problem:
put the table, Label, DropDownList etc. into the same UpdatePanel
or put them in another UpdatePanel and set the UpdateMode of that property to Always, so that it gets updated, even if a Postback was initiated by a control within another UpdatePanel.
See this page in MSDN for details.
You just need runat="server" on the label itself; though Visible should default to True.
Make sure you add a ForeColor to avoid mixing it in w/ background.
Debug to ensure your label has content and it's not in another control whose Visible=False.
If the table is changing visible and is the parent container of the label I don't believe it is necessary to change the label's visibility at all as it should always be set to visible.
I am assuming that you are gonna hide the ddl as well if there is no data. Have you tried putting a panel around both of them and setting its visibility to true
if you are returning rows and your button is in an updatepanel, then is your label and ddl in that updatepanel as well
thanks its really useful, put Lable in a update panel.
<ContentTemplate>
<table>
<tr>
<td>
<asp:LinkButton ID="LinkNM" runat="server" Text="Learn>" BackColor="Transparent" style=" color: #6699FF;text-decoration-color:none;border:none;font-size:x-large" OnClick="LinkNM_Click"/>
<asp:Label ID="lblChapterName" runat="server" BackColor="Transparent" style=" color: #6699FF;text-decoration-color:none;border:none;font-size:x-large" ></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnFileUpload" />
</Triggers>
</asp:UpdatePanel>

Categories

Resources