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
Related
I've seen multiple variations of this question asked, but all of the answers seem to involve javascript.
I'm querying a database, retrieving a list of items, and populating 3 different dropdown lists with the exact same content. After I select an item from a list, and click the "Save" button, I get an invalid postback error.
I'm certain it's because I'm using AutoPostBack on my DropDownList to trigger an update and disable a new selection in the other lists. When I set AutoPostBack to false, the error disappears.
I've read that I need to register my list content for event validation, but the examples I'm seeing, as mentioned above, are manually entered or handled with javascript; not server side from content generated by a DB query.
The solution I'm using now is a "link button" instead of a regular asp:button, since the former does not seem to cause a postback.
I would like to know if there is a more formal way of handling this. I'm not going to disable event validation, for security reasons.
<asp:UpdatePanel ID="DropDownListPanel" runat="server"
ChildrenAsTriggers="true" ><ContentTemplate>
<asp:gridview GridLines="Both" runat="server"
ShowHeader="false" ShowFooter="true" HorizontalAlign="Left"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField ControlStyle-Height="100%" ItemStyle-Width="25%">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
AppendDataBoundItems="true" Width="100%" AutoPostBack="true"
OnSelectedIndexChanged="CheckItem">
<asp:ListItem Value="-1">Select</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</Columns>
</asp:gridview>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="SaveButton" runat="server" Text="Save"
Enabled="True" OnClick="SaveTable" />
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.
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.
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.
To make certain form creation easier, we use a modified Formview control that is inside a User Control. This User Control is for a grid and a FormView, you can choose an item in the grid, and a FormView is presented in a modal for viewing/editing:
<I2CL:Grid runat="server" ID="Grid" OnSelecting="Selecting" ShowCreate="true" />
<I2:Modal ID="SFModal" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<I2:FormView runat="server" ID="FVSubForm" DefaultMode="Edit" DataSourceID="DSSubForm" />
<I2:ILDataSource ID="DSSubForm" runat="server" />
</ContentTemplate>
</I2:Modal>
In a page, the control looks like this:
<I2C:TabGrid ID="TG" runat="server" Property="ParentProperty">
<Columns>
<I2:Column Header="Column 1" DataSource="Column1" />
<I2:Column Header="Column 2" DataSource="Column2" />
</Columns>
<EditItemTemplate>
<I2Form:Dropdown ID="Col1" runat="server" SelectedValue='<%# Bind("Column1") %>' List="Column1Options" />
<I2Form:Textbox ID="Col2" runat="server" Text='<%# Bind("Column2") %>' />
</EditItemTemplate>
</I2C:TabGrid>
The problem is the EditItemTemplate we use. The only way I can figure out how to hook it up is to have an ITemplate in the TabGrid control and apply the reference in OnInit:
[PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(FormView))]
public ITemplate EditItemTemplate { get; set; }
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
FVSubForm.EditItemTemplate = EditItemTemplate;
}
The problem with this is that because the reference is to an object in the user control, the EditItemTemplate reference that ties to the dictionary entries in FormView for changes are destroyed, so when you get the dictionary of changes sent to the datasource, they're empty on every postback.
The I2:ILDataSource used here is a custom implementation closest to ObjectDataSource. Instead of a generic object call, it directly calls a GetEntity() in the page (or user control in this case) and a UpdateEntity(obj Entity) to save. Since it's a very specific scenario, we can eliminate 90% of the code in ObjectDataSource.
What I want to be able to do is point the <EditItemTemplate> in the <I2C:TabGrid> directly to the <EditItemTemplate> of the <I2:FormView> inside. Is this possible, or anyone have suggestions of another route to go?
Note: I tried exposing the EditItemTemplate on FVSubForm as a proxy property, but this didn't work because the property is set on the user control before the child control is created, so FVSubForm is null. If this can be worked around, I'm certainly all ears.
One thing you need to do is mark your ITemplate property as supporting two-way databinding:
[TemplateContainer(typeof(FormView), System.ComponentModel.BindingDirection.TwoWay)]
Without this, ASP.NET will not generate the proper code for the page that allows Bind() expressions to work.
I'm not sure if that's all you need, but that's something to try.
David