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.
Related
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.
I have a gridview which contains images (populated dynamically from database) and dropdownlist which contains two values. First column contains checkbox. I want to insert selected checkbox's images and dropdown values to a new table on button click. What may be the suitable way?
Here is the grid view:
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false" AllowPaging="true"
EmptyDataText="No images found" OnPageIndexChanging="gvDetails_PageIndexChanging" PageSize="5">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckUncheckAll"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID ="CheckBox2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="imgPreview" ImageUrl='<%#
"ImageHandler.ashx?imgID="+ Eval("ID") %>' runat="server"
Height="80px" Width="80px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dropdown" ItemStyle-Width="50px">
<ItemTemplate>
<asp:DropDownList ID="dpdListEstatus" runat="server" OnSelectedIndexChanged="dpdListEstatus_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
Loop with gridview rows
Find for the checkbox control
Check if its Checked property is true
If yes, call insert statement
Set the values you want to get from image and dropdownlist. Of course you need to use findcontrol on it too.
Dim cbSelect As CheckBox, imgToInsert As Image, ddlStatus As DropDownList
For Each r As GridViewRow In gvDetails.Rows
cbSelect = r.Cells(0).FindControl("CheckBox2")
If cbSelect.Checked Then
imgToInsert = r.Cells(1).FindControl("imgPreview")
ddlStatus = r.Cells(2).FindControl("dpdListEstatus")
'Insert statement goes here...
End If
Next r
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.
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"
My DataGrid contain totally 32 columns.I need to display my first 4 column as default column.
For the remaining Column i need to view using scroll bar.(not Page scroll need scroll bar inside my grid view)
When I've had to do this, what I did was create 2 Gridviews next to each other
The first Gridview should have only the freezable columns. The second will have the rest, and will be in a scrollable div tag.
I had defined amount of of rows, so it wasn't a problem for me, but if you scroll down on one grid, the rows won't match the second grid.
Here's another solution using CSS..but I haven't tried it:
http://www.codeproject.com/KB/webforms/FreezePaneDatagrid.aspx
If you use third party controls like the Telerik RadGrid, they usually have built in properties to control Freezing Columns.
Try this
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField HeaderText="Column 1" />
<asp:BoundField HeaderText="Column 2" />
<asp:BoundField HeaderText="Column 3" />
<asp:BoundField HeaderText="Column 4" />
<asp:TemplateField>
<ItemTemplate>
<div style="overflow: scroll; width: 400px;">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Column 5") %>'></asp:Label>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Column 6") %>'></asp:Label>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("Column 7") %>'></asp:Label>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("Column 8") %>'></asp:Label>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("Column 9") %>'></asp:Label>
....
<asp:Label ID="Label7" runat="server" Text='<%# Eval("Column 32") %>'></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>