How to wrap the DropDownList in the GridView FooterTemplate? - c#

Please help me to fix the issue with wrapping the text in asp.net GridView FooterTemplate.
I am alyready wrapping <ItemTemplate> and <EditItemTemplate> using the below command
<asp:TemplateField ItemStyle-Wrap="true"
but the same code is not working for the FooterTemplate.
Please see the below code
<asp:TemplateField ItemStyle-Width="120px" HeaderText="Bureau" ItemStyle-Wrap="true">
<ItemTemplate>
<asp:Label ID="lblBureau" runat="server" Text = '<%# Eval("Bureau_Ref_Type")%>'
></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblBureauEdit" runat="server" Visible="false" Text = '<%# Eval("Bureau_Ref_Id")%>'></asp:Label>
<asp:DropDownList ID="ddlBureauEdit" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlBureauFooter" runat="server">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
If i reduce the size in the FooterTemplate Dropdowlist items text page seems to fit in 1024 px resolution,but our client wants the same resolution with out reducing the Item text size. So i need all experts to help wrapping the items in the FooterTemplate.
Thanks
Sam

You need to use the FooterStyle to style that section. Your ItemStyle settings only apply to actual data items (not footers or headers).
You could rewrite the first section of your markup like this:
<asp:TemplateField HeaderText="Bureau">
<ItemStyle Width="120px" Wrap="true"></ItemStyle>
<FooterStyle Wrap="true"></FooterStyle>
<ItemTemplate>
...
Notice that I moved your ItemStyle settings into the <ItemStyle> settings block, as well as adding the <FooterStyle> settings block.

Related

Accessing Header Text property of GridView TemplateField in the Code Behind when it is set from Header Template

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.

Set Item limit to be display in ajaxToolkit ComboBox or set the Combobox position downwards in asp.net

I have a ajaxtoolkit combobox inside a gridview and it works perfectly, but the problem is when I click the dropdown button the list overlaps the page so I want to limit the number to be displayed to 10 items per scroll. Next problem is when I try to add an update panel to the page, It destroys the rendering of the combobox. How can I solve this? Thanks in advance
here is my code for the combobox inside the gridview
<asp:GridView CssClass="pad" ID="dgvOrder" runat="server" BorderStyle="Double" AutoGenerateColumns="False" OnRowDataBound="dgvOrder_RowDataBound" OnRowDeleting="dgvOrder_RowDeleting" HorizontalAlign="Center" >
<Columns>
<asp:TemplateField HeaderText="No." AccessibleHeaderText="No.">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Description" AccessibleHeaderText="Description">
<ItemTemplate >
<ajaxToolkit:ComboBox ID="ddlItems" AutoPostBack="True" AppendDataBoundItems="True" onmouseover="this.size=4;" onmouseout="this.size=1;" DataTextField="item_desc" DataValueField="item_id" runat="server" AutoCompleteMode="Suggest" ItemInsertLocation="Prepend" OnSelectedIndexChanged="ddlItems_SelectedIndexChanged" DropDownStyle="DropDown" BorderStyle="Double" ></ajaxToolkit:ComboBox> <br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please pick an item" ControlToValidate="ddlItems"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Inventory Code" HeaderText="Inventory Code">
<ItemTemplate>
<asp:Label ID="lblInvCode" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Qty" HeaderText="Qty">
<ItemTemplate>
<asp:TextBox ID="txtQty" runat="server" OnTextChanged="txtQty_TextChanged" AutoPostBack="True" onkeyup ="ValidateText(this);"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator23" runat="server" ErrorMessage="Please input qty" ControlToValidate="txtQty"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="UOM" HeaderText="UOM">
<ItemTemplate>
<asp:Label ID="lblUOM" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="SOQ" HeaderText="SOQ">
<ItemTemplate>
<asp:Label ID="lblSOQ" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField AccessibleHeaderText="Reason" HeaderText="Reason">
<ItemTemplate>
<asp:TextBox ID="txtReason" runat="server" Enabled="False"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
and here is my code for the updatepanel
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
<Triggers>
(whole page inside)
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="txtIdNo" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
Long Item Lists / Multiple Input Controls
All of the items in a ComboBox's list will be rendered to the web page it exists in. The AutoCompleteExtender, on the other hand, retrieves items from its ServiceMethod after the page is rendered. When your ComboBox contains a rather long list of items, or when you have a relatively large number of ComboBoxes on the same page (or within the same UpdatePanel), load times could be slowed down significantly. When ComboBoxes perform slowly because of the amount of markup they must render to the browser, an AutoCompleteExtender can be used instead to increase performance.
<ajaxToolkit:ComboBox ID="ComboBox1" runat="server"
DropDownStyle="DropDown"
AutoCompleteMode="None"
CaseSensitive="false"
RenderMode="Inline"
ItemInsertLocation="Append"
ListItemHoverCssClass="ComboBoxListItemHover"
<asp:ListItem>...</asp:ListIem>
...
For more information your can look it in this link.

Increase header width and its items

I am trying to increase the width size of header text and its contents. I am using the below code and when I try to increase there is no change happening in the page. How can I do that? Am I going wrong anywhere?
<asp:TemplateField HeaderText="Remedy" HeaderStyle-Width="150" ItemStyle-Width="150">
<ItemTemplate>
<asp:Label ID="lblRemedy" runat="server" Text='<%# Eval("Remedy") %>'></asp:Label>
<asp:TextBox ID="txtRemedy" runat="server" ReadOnly="true" Text='<%# Eval("Remedy")% >' Visible="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
Maybe specifying a proper measurement unit would help. Try to specify pixels as measurement unit and see what happens...
<asp:TemplateField HeaderText="Remedy" HeaderStyle-Width="150px" ItemStyle-Width="150px">

Selected rows using check box should be displayed inside the footer row

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.

Javascript Breaking on < & > in a GridView edit box

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"

Categories

Resources