apply a condition in html based on a boundfield - html

I have a gridview and a command field that is a link to a page. How can I replace the link with just text based upon an field in the record?
Here is the code:
<asp:CommandField SelectText="View" ShowSelectButton="True">
<ItemStyle Width="50px" />
</asp:CommandField>
So I want to replace the CommandField with "N/A" for a record that meets a criteria of Date<2015. Where Date is a field in the record.
Thank you.

This is task worth a custom template field. I'd suggest to have both controls in the template, and show either one or the other based on your condition. Something like this:
<TemplateField>
<ItemTemplate>
<asp:Literal Text="N/A" runat="server" Visible='<%# ((DateTime)Eval("FieldName")).Year < 2015 %>'>
<asp:Button Text="View" CommandName="Select" runat="server" Visible='<%# (int)Eval("FieldName") >= 2015 %>'>
</ItemTemplate>
</TemplateField>
So as you can see the literal with N/A text and the button basically alternate visibility based on the condition.

Related

How To Display CKEditor Data In Stimulsoft? and In WebForm Grid View?

How To Display CKEditor Data In Stimulsoft? and In WebForm Grid View ?
I Use CkEditor to Save My Data In SQL then Data Saved as HTML Tags In Database
When I want to Display Data In StimulSoft
My data Show As HTML Tag . but I want to Display with out Html Tags.
Well, for the most part, you can directly display such content on a web page.
In most cases, even a simple label dropped onto the form will correctly render that column of data.
Say we have a simple GridView like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID"
CssClass="table table-hover" Width="50%" GridLines="None"
ShowHeaderWhenEmpty="true">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="HotelName" HeaderText="HotelName" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField HeaderText="Info">
<ItemTemplate>
<asp:Label ID="lblMarkUp" runat="server" width="340px"
Text='<%# Eval("ImageInfo") %>' >
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="cmdEdit" runat="server" Text="Edit" CssClass="btn myshadow"
OnClick="cmdEdit_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and out code beind to load is this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid()
End If
End Sub
Sub LoadGrid()
Dim strSQL As String = "SELECT * FROM tblHotelsP ORDER BY HotelName"
GridView1.DataSource = Myrst(strSQL)
GridView1.DataBind()
End Sub
So, all we did was shove a data table right into the grid.
However, note that ONE column we have. I don't have ckedit installed, but I do have the ajaxtoolkit HTML editor. The results will be the same. We "save" that one column right into the database.
So, in most cases, any markup, and even ctrl-v to paste in a picture will work.
The results of the above grid are thus this:
A text box will not work, but a label will as per above.
You can also say use a content placeholder or whatever. However, I find just a simple label control works rather well in most cases (as the above example grid using a label shows)

<a href> tag in TextBox in GridView

This is not a pretty application by any stretch. It's only meant for a select few to use in the office and does not require street appeal. With that said...
I have a gridview with the following template column:
<asp:TemplateField HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblAction" runat="server" Text='<%#(Eval("Action"))%>'
ToolTip="Action to be Taken"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAction" runat="server"
TextMode="MultiLine" Width="450px" Height="100px" ValidationGroup="UpdateFU"
Text='<%#Eval("Action")%>'
CssClass="RequiredText" ToolTip="Follow-Up Action">
</asp:TextBox>
<asp:RequiredFieldValidator ID="rfv_txtAction" runat="server"
ControlToValidate="txtAction" ErrorMessage="FollowUp Action is Required"
Text="*" ValidationGroup="UpdateFU">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAction" runat="server"
TextMode="MultiLine" Width="250px"
ValidationGroup="UpdateFU"
CssClass="RequiredText"
ToolTip="Follow-Up Action">
</asp:TextBox>
<asp:RequiredFieldValidator ID="rfv_txtAction" runat="server"
ControlToValidate="txtAction" ErrorMessage="FollowUp Action is Required"
Text="*" ValidationGroup="AddFU">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
For the example that is causing me trouble, the data in the field that is bound to this column is: **Testing with a link. Google**
The label in the ItemTemplate displays as I expect it to. The regular text is not hyperlinked and the hyperlink text is. Please see the included image:
ItemTemplate
When my row is in Edit mode, it also displays in the TextBox as I would suspect. Please see the included image: EditItemTemplate
When I attempt to Save or Cancel the record, the gridview does not recognize that the command button was clicked. It just sits there. If I remove the text that references the tag (leaving from my example, **Testing with a link.**), it works beautifully. The only problem being that I can't save any text in the textbox with my link.
Any help is greatly appreciated.
I think you are using UpdatePanel around your GridView. That is why you are missing exceptions if you are not checking the browser console. And that exception could very well be A potentially dangerous Request.Form value was detected from the client
Fixes for that here
A potentially dangerous Request.Form value was detected from the client
A potentially dangerous Request.Form value was detected from the client
https://www.codeproject.com/Tips/297679/A-potentially-dangerous-Request-Form-value-was-det
https://www.aspsnippets.com/Articles/ASPNet-Error-A-potentially-dangerous-RequestForm-value-was-detected-from-the-client.aspx

Include a DropDown in RadToolBarDropDown

So I'm using Telerik's gui system and would like to insert a dropdown inside another one but I don't know how to do that.
This is what I've got so far
<telerik:RadToolBarDropDown runat="server" ToolTip="DropDown1" ImageUrl="~/Images/test.png">
<Buttons>
<telerik:RadToolBarButton runat="server" Text="Click me!" Value="TOGGLE_WALLS" CheckOnClick="true" ImageUrl="~/Images/checkmark.png"/>
</Buttons>
</telerik:RadToolBarDropDown>
More or less, a dropdown inside a dropdown. Is it possible? Do Telerik support this?
You can use an item template to nest a DropDownList or ComboBox in the RadToolBarDropDown:
<telerik:RadToolBarDropDown>
<Buttons>
<telerik:RadToolBarButton>
<ItemTemplate>
<telerik:RadDropDownList ID="RadDropDownList1" runat="server">
</telerik:RadDropDownList>
</ItemTemplate>
</telerik:RadToolBarButton>
</Buttons>
</telerik:RadToolBarDropDown>

Unable to get selected option from a select field with a repeater (ASP.net / Sitecore)

I am working with an ASP repeater to get the elements from a Sitecore multi-list field (see code below). When the form is submitted, I can't pull the value of the selected option. Trying to add an ID and runat="server" to the element breaks the code because the repeater also has runat="server".
I'm very new to ASP, but it seems there has to be an option to pull the value of a selected field in a form.
This is the code:
<asp:Repeater ID="rptSubjectSelect" runat="server" OnItemDataBound="rptSubject_ItemDataBound">
<HeaderTemplate>
<select data-id="select" class="dropdown-component--select">
</HeaderTemplate>
<ItemTemplate>
<option value="<%# ((Sitecore.Data.Items.Item)Container.DataItem)["TextSubject"].ToString() %>"><%# ((Sitecore.Data.Items.Item)Container.DataItem)["TextSubject"].ToString() %></option>
</ItemTemplate>
<FooterTemplate>
</select>
</FooterTemplate>
</asp:Repeater>
I'd recommend that instead of using a repeater this way (to manually build an HTML select input), use an ASP dropdown control.

GridView Centering Issues

How can I center the text of the rows of an <asp:GridView /> that gets populated at run-time?
I have tried RowStyle-HorizontalAlign="Center" and similar things that I have found in this site to no avail.
Similarly, I cannot center a GridView inside a div—that is, <div><asp:GridView /></div>—to save my life.
Am I using a bunch of deprecated functions or what? Also, Chrome is my default browser.
I am aware that a thousand questions in the gist of mine have been asked before, but all that I have tried are either years old or are not working.
Thanks in advance!
Are you using bound columns or autogenerated? If you're binding them in your markup, something like this should work fine (this is an actual example from something of mine):
<asp:TemplateField HeaderText="External Id" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<EditItemTemplate>
<asp:TextBox ID="txtExternalId" runat="server" Text='<%#Bind("ExternalId")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewExternalId" runat="server" Width="100%" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblExternalId" runat="server" Text='<%#Bind("ExternalId")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>