In Insert Mode I want to show one kind of Template and Edit Mode I want to show another Kind of Template in Devexpress Control in C#.NET
This can be implemented using the following approach:
You should define the EditFormTemplate so that it contains a different set of editors for the Insert and Edit functionality. Handle the HtmlRowCreated event to hide non required editors based on the ASPxGridView's IsNewRowEditing property value.
Check out the sample project on this issue which demonstrates the solution based on user controls and binding expressions. In this solution, the EditForm template contains two user controls with the Visible property bound to the ASPxGridView.IsNewRowEditing property:
[HTML]
<uc1:Edit id="Edit1" runat="server" Visible="<%# !Container.Grid.IsNewRowEditing %>"></uc1:Edit>
<uc2:Insert id="Insert1" runat="server" Visible="<%# Container.Grid.IsNewRowEditing %>"></uc2:Insert>
Btw, this issue might also be helpful. If you need more help, please contact the DevExpress support team here.
Use an ASP template field and individual item templates inside your gridview
<asp:TemplateField id="test" runat="server">
<ItemTemplate>
<ItemTemplate>
test
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Text="test" runat="server"/>
</EditItemTemplate>
</ItemTemplate>
</asp:TemplateField>
I did the above from memory. Heres a link to an example i found as well:
http://programming.top54u.com/post/ASP-Net-GridView-Edit-ItemTemplate-Mode.aspx
Related
It seems like there is HeaderTemplate and ItemTemplate and EditItemTemplate within the TemplateField at the code which I am examining.
What else can exists with <asp:TemplateField> apart from HeaderTemplate and ItemTemplate and EditItemTemplate?
They are in effect a means to "drop in" standard asp.net controls into quite a few of the data aware controls.
So, GridView, Datagrid, Repeater and a few more require this to allow dropping in of standard controls to render.
So, for a Gridview, you can drop in plane jane asp.net controls, but to do so, you require to wrap those plane jane controls in what is called a "Template".
so for a grid, you might see this:
Note the template field for a simple check box. So, when we run this, we get this:
So, the template has featuers like "HeaderText" etc.
However, if you use a newer ListView? Then you don't need to use Template fields, and if you only have say a few template fields, then a GridView is fine. However, if you have say a boatload of asp.net controls you want in that Grid, then I perfer a ListView.
So, this template field lets you define header text, formatting, justification etc.
so, for example, the above check box don't look good - not center, so you can add this to the markup:
<asp:BoundField DataField="HotelName" HeaderText="HotelName" />
<asp:TemplateField HeaderText="Active" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
Checked='<%# Eval("Active") %>' />
</ItemTemplate>
</asp:TemplateField>
And now we get this:
So for a data repeater, Dataview, Gridview and a few more, then they have build in data bound controls (BoundField), but often we want to use controls like a drop down list, a picture, or whatever in the markup - so you have to wrap the plane jane asp.net control(s) each in a template field, and this lets you define the heading for the grid, the justification etc.
in my webpage different users can visit same profile, but users can be ither Owner of a profile, or Visitors, and content have to change for those two conditions.
if visitor check profile he see this editor:
<asp:Repeater id="UserLoginRepeater" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server">label Text</asp:Label> <asp:Label runat="server">label text 2</asp:Label>
</br>
<asp:Button runat="server" Text="TestButton"/>
</br>
<asp:Label ID="Label3" runat="server">Test</asp:Label> <textarea><%# Eval("Content") %></textarea>
</br>
</br>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
codebehinde:
if User is Owner of a profile TextArea have to be replaced by a label and an other label with textbox have to be added.
I found couple of possible implementations of this on internet, but they are not so easy to maintain. for example
http://tinyurl.com/9764eys
What would be the best way to Load controls dynamicly into Repeater?
Use a <asp:ContentPlaceholder> then in your code behind add a handler for the OnItemDataBound event. If you want those controls to handle events, make sure you bind your repeater before OnPreRender for the page.
Why not just create two repeaters for two conditions?
Just bind the repeater for the specific user and hide the other one.
Made Dynamic load of Controllers in code-behinde.
I looking forward to find a suitable asp.net DataBound control (C#) to implement in my application.
I wanted to create a exam page where each page show 10 questions, each question got a Label control and a radiobutton control to display the choices, the data to be bind into the DataBound control might be having multiple rows where each rows represent each question.
I found that DetailView control was quite suit with my requirement but I not able to set the page size.
Please help to give some suggestion and advises, thank you in advanced.
I would use a DataList or a ListView, because it will allow you to enter a template for each item. The reason I would choose these over a repeater is because you can use data keys, which will probably come in handy.
Here's a simple example of how you could implement a list of questions:
<asp:DataList ID="DataList1" runat="server" DataKeyField="QuestionID" ...>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Question")%>' />
<asp:RadioButton ID="RadioButton1" runat="server" Text="Yes" GroupName="QuestionAnswer" ... />
<asp:RadioButton ID="RadioButton2" runat="server" Text="No" GroupName="QuestionAnswer" ... />
</ItemTemplate>
</asp:DataList>
I would recommend to you to use the Repeater control since you can customize it's design very easily to suit your needs.
Here are two tutorials on how to use it:
http://www.w3schools.com/aspnet/aspnet_repeater.asp
http://www.learn-asp.net/asptutorials/Repeater.aspx
Update:
Repeater doesn't have pagination included so you would have to add it:
http://blog.divergencehosting.com/2009/03/25/adding-paging-repeater/
Other option would be to just use a GridView which has pagination included.
I am using ListView control in ASP.NET to retrieve data from my database. I studied web form codes for my ListView control and figured out that it basically makes labels to show my data retrieved from the database. I wonder how I can manipulate the label. I can easily change the font color of the label, but I cannot make the label to truncate and show "(..more)" if its length goes more than 10 without resorting to C# code. (I could not find the labels in .cs page.) Is there anyway I can manipulate the C# codes of the labels automaticaly generated by ListView control? Pease let me know. Thanks in advance!
Below is my ListView control in C#
<asp:ListView ID="Posts" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<span>
<asp:Label ID="subjectLabel" runat="server" Font-Bold="True" Font-Size="Large" Text='<%# Eval("subject") %>' />
<br />
<asp:Label ID="contentsLabel" runat="server" Font-Size="Small" ForeColor="#666699" Text='<%# Eval("contents") %>' />
<br />
<br /></span>
</ItemTemplate>
If you really want to avoid doing it in code, you could always do it in the SQL that provides the data:
SELECT CASE WHEN Len(contents) > 10 THEN Left(contents, 10) + '...' ELSE contents END
FROM YourTable
WHERE whatever
But you can do it in the databinding Eval() using the ternary operator if you don't want to use code-behind.
in the code behind page u need to bind the listview control with the datatable which u are fetching like,
Posts.Datasource=dt;
Posts.Databind();
where dt is the datatable which u are fetching using sql query.can give more explanation once u write the question more elaborately
My page looks correct in Firefox and IE8. But in IE7, a nested gridview spills into the adjacent cell, much like the issue here.
Looking at it in the developer tools, there is an inline-style associated with the table that ASP.NET generated, and it has a width attribute of 100%. If I remove this, the nested table pops back where it belongs.
Problem is, nowhere is an inline-style set. In fact, if I try to set width='250px', it gets overridden with width='100%'. If I try to remove the width attribute in the code-behind, attrGridView.Attributes["Width"] is null, and calling .Remove() does nothing. But every asp.net-generated gridview-table has an inline style with width='100%' set on it (it's only causing me issues in one place).
Setting table-layout='fixed', as suggested in the article I linked to, did not help.
How do I get ASP.NET to stop setting this property?
Some code:
<asp:TemplateField HeaderText="Attributes" SortExpression="Attributes">
<HeaderStyle CssClass="GridHeaderCell" />
<ItemStyle CssClass="GridTableCell AttrGridCellPadding" />
<ItemTemplate>
<asp:GridView id="attributesGridView" runat="server"
AutoGenerateColumns="false" ShowHeader="false" GridLines="None"
AlternatingRowStyle-BackColor="White" CssClass="StupidGridView" >
<EmptyDataTemplate>
<p class="italic">There are no attributes for this request.</p>
</EmptyDataTemplate>
<Columns>
<asp:TemplateField>
<ItemStyle CssClass="AttrTableCell" />
<ItemTemplate>
<asp:Label id="attributeName" runat="server"
Text='<%# Eval("Name") + ": "+ Eval("Value") %>'
CssClass="AttrGridCell"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
.StupidGridView {
width: 250px;
}
Themes are being applied and overriding control-level settings. Check theme settings on page, web.config, or anywhere else a theme may be set.
Unfortunately, the ASP.NET html rendering is really bad.
Microsoft know that and provided Control adapters in 2006 which allow you to modify control rendering.
Instead of searching on how to override what ASP.NET render, I would advise to use CSSFriendly which provides control adapters for most ASP.NET bad-rendered controls.
If you don't need "pure-css rendering" and CSS afraid you, you can check how they do to create your own adapter.
ScottGu post on this subject from google.