I want to use DropDownCheckBoxes control in EditItemTemplate of my TemplateField. When I put it in normal ItemTemplate - it works. But when DropDownCheckBoxes is in EditItemTemplate - it doesn't appears...
"Select" is the only word that appears in the place where should be my DDCB.
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" ID="lblTest" Text='<%# Bind("test") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownCheckBoxes ID="ddcbTest" runat="server"></asp:DropDownCheckBoxes>
</EditItemTemplate>
</asp:TemplateField>
Have you ever tried to use DropDownCheckBoxes in EditItemTemplate?
Related
I have a GridView in an asp .net application, where the Header Text of a template field is set in the Header Template of the field, as a label (where it will come from the resource file). Below is the code
<asp:GridView ID="gridView" ClientIDMode="Static" runat="server" AutoGenerateColumns="False" meta:resourcekey="grdViewResource">
<Columns>
<asp:TemplateField meta:resourcekey="TemplateFieldResource1">
<HeaderTemplate>
<asp:Label ID="lblNameHeader" Text="Name" runat="server" meta:resourcekey="lblNameHeaderResource1"/>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblNameValue" Text='<%# Eval("Name") %>'/>
</ItemTemplate>
</Columns>
</asp:GridView>
In code behind I am trying to access the HeaderText set on the column like this
var headerText = gridView.Columns[0].HeaderText;
But the value is coming Empty and I am not able to retrieve it from the gridView.Columns' HeaderTemplate property as well.
Please help me.
You have several problems with your code.
You are missing a closing </asp:TemplateField>. Your asp:Label is missing a runat="server" attribute.
If you want to use the .HeaderText property, this should be your markup:
<asp:GridView ID="gridView" ClientIDMode="Static" runat="server" AutoGenerateColumns="False" meta:resourcekey="grdViewResource">
<Columns>
<asp:TemplateField meta:resourcekey="TemplateFieldResource1" HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblNameValue" Text='<%# Eval("Name") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
If you want to use a HeaderTemplate with custom markup in it, then you need to cast the column to a TemplateField, then access the controls within it.
I have requirement when we select the rows of the gridview using checkbox those selected rows should be displayed in the footer row of the grid
please let me know how we can do it using asp.net and c# programming.
<asp:GridView runat="server" ID="gv" AutoGenerateColumns="False" CellPadding="4">
<Columns>
<asp:TemplateField HeaderText="Username">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Username") %>'></asp:Label>
<asp:HiddenField ID="hdn" runat="server" Value='<%#Eval("Id") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Username") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ftrtxtunme" runat="server" Text='<%#Eval("Username") %>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You will have to perform a sort of the whole grid on the specific rows. I'm not sure wheter the Checked state will make it on top or bottom but if it does not work simply change Descending to Ascending.
First select the event in which you want the sorting to be called. Let's imply it's on some button click here.
myButton.Click += (s, e) =>
{
myDataGridView.Sort(dataGridViewCheckBoxColumn, ListSortDirection.Descending);
};
You might want to check the SortMode Property before sorting the grid.
I have binded a grid with List (temporary list),
how can I pick the list text into controls text in item template in grid view.
aspx
<asp:GridView ID="gvDenomination" runat="server">
<Columns>
<asp:TemplateField HeaderText="Value">
<ItemTemplate>
<asp:Label ID="lblValue" runat="server" Text='<%#Eval("lstdenomination") %>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton runat="server">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
CodeBehind
stdenomination.Add(Convert.ToInt32(txtDenomination.Text));
gvDenomination.DataSource = lstdenomination;
gvDenomination.DataBind();
If I get you, lstdenomination is a List<int>. You can do this
<asp:TemplateField HeaderText="Value">
<ItemTemplate>
<asp:Label ID="lblValue" runat="server" Text='<%# Container.DataItem %>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
I have a column that has an ImageButton. my database field has bit data type. I want when my record has true value in that column show True.jpg and my command become MakeFalse and when it has false value show False.jpg and my command become MakeTrue. How I can do this?Is it possible to do it with one TemplateField?
thanks
You could include two ImageButtons in a TemplateField and evaluate Visible from your bit_field
<asp:TemplateField HeaderText="YourField">
<ItemTemplate>
<asp:ImageButton runat="server" ImageUrl="True.jpg" Visible='<%# (bool)Eval("bit_field") %>' />
<asp:ImageButton runat="server" ImageUrl="False.jpg" Visible='<%# !(bool)Eval("bit_field") %>' />
</ItemTemplate>
</asp:TemplateField>
I'm not sure how you'd want your Command to tie in.
This is the remaining part of the above Brissles code
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Select" Text='<%#(bool)Eval("bit_field")? "Make False":"Make True" %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
I've got an Asp.Net GridView inside an UpdatePanel. It all works fine, except when one of the columns includes HTML special characters like < and >. The GridView is bound to a List<Entity> and the Entity class has a property Regex which is a System.Text.RegularExpressions.Regex.
At first I had this:
<asp:TemplateField HeaderText="RegEx">
<ItemTemplate>
<asp:Label ID="RegExLabel" runat="server" Text='<%#Eval("Regex") %>'
ToolTip='<%#Eval("Regex") %>' Width="102px" CssClass="Wrap" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="RegExTextBox" runat="server" Text='<%#Eval("Regex") %>'
Width="98px" />
</EditItemTemplate>
</asp:TemplateField>
With a value of (?<capture>\d+) this displayed ?\d+ when not editing, and when editing this row I got a script error and the edit, update and cancel buttons no longer work.
Then I tried the answer in this question and had this:
<asp:TemplateField HeaderText="RegEx">
<ItemTemplate>
<asp:Label ID="RegExLabel" runat="server"
Text='<%#System.Web.HttpUtility.HtmlEncode(Eval("Regex").ToString()) %>'
ToolTip='<%#System.Web.HttpUtility.HtmlEncode(Eval("Regex").ToString()) %>'
Width="102px" CssClass="Wrap" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="RegExTextBox" runat="server"
Text='<%#System.Web.HttpUtility.HtmlEncode(Eval("Regex").ToString()) %>'
Width="98px" />
</EditItemTemplate>
</asp:TemplateField>
This is slightly better, in that the tooltip and the non-editing version display correctly, but when I start editing I see: (?<capture>\d+) with the HTML Entities displayed raw. Does anyone know a way to encode the values (to stop the script error) while still displaying them correctly without the HTML entities in their raw state when editing?
<asp:TemplateField HeaderText="RegEx">
<ItemTemplate>
<asp:Literal Mode="Encode" ID="RegExLabel" runat="server" Text='<%#Eval("Regex") %>'
ToolTip='<%#Eval("Regex") %>' Width="102px" CssClass="Wrap" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="RegExTextBox" runat="server" Text='<%#Eval("Regex") %>'
Width="98px" />
</EditItemTemplate>
</asp:TemplateField>
and in the page directive add this ValidateRequest="false"