How to get rows which selected by user in telerik rad grid? - asp.net

I hava a Rad Grid like this :
<tel:GeneralRadGrid ID="MainGridView" runat="server" AllowMultiRowSelection="True"
OnItemCommand="MainGridView_OnItemCommand"
GroupingEnabled="false"
OnItemCreated="MainGridView_OnItemCreated"
MasterTableView-CommandItemSettings-ShowAddNewRecordButton="false"
DataSourceID="GridDataSource">
<MasterTableView DataKeyNames="Id">
<Columns>
<telerik:GridClientSelectColumn runat="server" UniqueName="ClientSelectColumn" >
</telerik:GridClientSelectColumn>
<telerik:GridBoundColumn DataField="mNumber" HeaderText="<%$Resources:Public,Number%>" UniqueName="Number" HeaderStyle-Width="10%" FilterControlWidth="80%" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
<telerik:GridBoundColumn DataField="Name" HeaderText="<%$Resources:Public,NikName%>" UniqueName="Name" HeaderStyle-Width="17%" FilterControlWidth="80%" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
</Columns>
</MasterTableView>
<ExportSettings IgnorePaging="True" ExportOnlyData="True"></ExportSettings>
</tel:GeneralRadGrid>
I added AllowMultiRowSelection="True" and <telerik:GridClientSelectColumn runat="server" UniqueName="ClientSelectColumn" > </telerik:GridClientSelectColumn>
for selecting multi rows, but i can not get selected rows,
How can i do it?

Where do you want to get the selected rows - on the client or on the server?
On the client you can use the get_selectedItems() method on the RadGrid client-side object.
On the server you can use the SelectedItems property which returns a GridItemsCollection.

Related

What is use of Datanavigateurlformatstring of hyperlink in gridview?

How to use Datanavigateurlformatstring of hyperlink in gridview?
I want to display page with the name of product like
http://localhost:55724/Admin/Category/Update/computer when I clicked on computer in gridview, it says resource not found.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="id" HeaderText="Id" />
<asp:HyperLinkField DataNavigateUrlFields="id"
DataTextField="Productname"
HeaderText="Product"
Target="_blank"
NavigateUrl="Searchdetails.aspx?product={0}"
DataNavigateUrlFormatString="~/Product/Searchdetails.aspx?product={0}" />
</Columns>
</asp:GridView>
How to fix this error.

How to validate controls in each column of a gridview

I would like to validate columns in an asp:Gridview but am unsure how to do so as all the tutorials I have found show a previous version on Microsoft Visual Studio (I am using 2010).
How do I validate each column of the Gridview?
Thanks
This is the code of my Gridview generated by visual studio.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="registrationNo" DataSourceID="SqlDataSource3"
onselectedindexchanged="GridView2_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="fullName" HeaderText="fullName"
SortExpression="fullName" />
<asp:BoundField DataField="address" HeaderText="address"
SortExpression="address" />
<asp:BoundField DataField="work" HeaderText="work"
SortExpression="work" />
<asp:BoundField DataField="home" HeaderText="home" SortExpression="home" />
<asp:BoundField DataField="mobile" HeaderText="mobile"
SortExpression="mobile" />
<asp:BoundField DataField="registrationNo" HeaderText="registrationNo"
InsertVisible="False" ReadOnly="True" SortExpression="registrationNo" />
<asp:ButtonField ButtonType="Button" CommandName="Edit" HeaderText="Edit"
ShowHeader="True" Text="Edit" />
<asp:ButtonField ButtonType="Button" CommandName="Update" HeaderText="Update"
ShowHeader="True" Text="Update" />
<asp:ButtonField ButtonType="Button" CommandName="Delete" HeaderText="Delete"
ShowHeader="True" Text="Delete" />
</Columns>
<HeaderStyle BorderColor="#33CC33" />
<RowStyle BorderStyle="Double" Font-Names="Monotype Corsiva" />
</asp:GridView>
//native asp.net clientside validation (ATLAS Ajax)
Instead of using BoundFields you should use TemplateField. This will allow you to add Validation controls in the field i.e.
Tutorial from 2007 which is still pertinent to this question
//serverside validation
In order to validate the values on the server side you have a couple of options:
a) add a CustomValidator pointing to codebehind server validation method i.e. msdn doc
b) on the gridviews RowUpdating method you could validate manually (this would also be for batch updates)

Accessing Radgrid items on parent page from a usercontrol

I have several pages that share a user control. When the user clicks a save button on the user control, I need to be able to loop the items of a Radgrid on the parent page and get the selected items. The radgrid has a checkbox column. I can see that I am getting values from the grid cells but for some reason the checked value on the checkbox is always false even when it is checked. This same foreach code works when called from the parent page itself but not from the usercontrol.
Here is a code snippet.
RadGrid ProjectGrid = (RadGrid) this.Parent.FindControl("ProjectGrid");
foreach (GridDataItem item in ProjectGrid.MasterTableView.Items)
{
string applicationPackageId = item.Cells[4].Text.ToString();
CheckBox chbx = item.FindControl("ProjectGridCheckBox") as CheckBox;
if (chbx != null && chbx.Checked)
{
numCheckedPackages++;
}
}
Here is my grid.
<telerik:RadGrid ID="ProjectGrid" runat="server" Skin="WF" ShowHeader="true" EnableEmbeddedSkins="false" AllowSorting="false" AllowFilteringByColumn="false" AllowMultiRowSelection="true">
<MasterTableView Width="100%" CommandItemDisplay="None" AutoGenerateColumns="false" TableLayout="Fixed">
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn Resizable="False" Visible="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridTemplateColumn UniqueName="SelectColumn" DataField="Id" HeaderStyle-Width="5%" >
<ItemTemplate>
<asp:CheckBox ID="ProjectGridCheckBox" runat="server"/>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Package.ProjectPackageNumberNameDisplayField" HeaderText="Project - Package" UniqueName="ProjectPackages" HeaderStyle-Width="85%"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ApplicationPackageID" HeaderText="Id" HeaderStyle-Width="15%" UniqueName="PackageId"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings EnableRowHoverStyle="true">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<HeaderStyle BackColor="#666666" Font-Names="verdana, arial" Font-Size="Small" Height="20px" />
</telerik:RadGrid>

Extra space at the end of a Telerik RadGrid

I have a Telerik RadGrid on my aspx web page. I notice that when I run my web application I get an extra space at the end as the below picture illustrates. I'm not sure why this shows up, I checked the markup and there is no extra column, hidden or otherwise, after the last column with the Drop link. I also looked at the RadGrid properties and there's nothing there that seems to indicate that there's anything additional that is being rendered. That extra space does not show up in the visual designer, so I'm not sure what is causing it. Any help is appreciated.
Markup for the RadGrid is shown below:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemCreated="RadGrid1_ItemCreated"
OnDeleteCommand="RadGrid1_DeleteCommand" GridLines="None" AllowSorting="True"
Skin="Web20" PageSize="20" FooterStyle-Wrap="false" >
<MasterTableView EditFormSettings-PopUpSettings-Modal="True" EditMode="PopUp" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False" DataKeyNames="ID" ShowFooter="True" AllowPaging="True">
<Columns>
<telerik:GridBoundColumn DataField="Date Submitted" DataType="System.DateTime" HeaderText="Date Submitted"
ReadOnly="True" SortExpression="Date Submitted" UniqueName="Date Submitted">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ReqCategory" HeaderText="ReqCategory" SortExpression="ReqCategory"
UniqueName="ReqCategory" Visible="False">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Title" HeaderText="Title" SortExpression="Title"
UniqueName="Title">
</telerik:GridBoundColumn>
<%-- <telerik:GridBoundColumn DataField="Description" HeaderText="Description"
SortExpression="Description" UniqueName="Description">
</telerik:GridBoundColumn>--%>
<telerik:GridBoundColumn DataField="Owner" HeaderText="Owner" SortExpression="Owner"
UniqueName="Owner">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Requestor" HeaderText="Requestor" SortExpression="Requestor"
UniqueName="Requestor">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Status" HeaderText="Status" SortExpression="Status"
UniqueName="Status">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Requested Completion" HeaderText="Requested Completion"
SortExpression="Requested Completion" UniqueName="Requested Completion">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Estimated Completion" HeaderText="Estimated Completion"
SortExpression="Estimated Completion" UniqueName="Estimated Completion">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Ticket Submitted By" HeaderText="Ticket Submitted By"
SortExpression="Ticket Submitted By" UniqueName="Ticket Submitted By">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="View Ticket" UniqueName="TemplateViewColumn">
<ItemTemplate>
<asp:HyperLink ID="ViewLink" runat="server" Text="View"></asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Edit Ticket" UniqueName="TemplateEditColumn">
<ItemTemplate>
<asp:HyperLink ID="EditLink" runat="server" Text="Edit"></asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridButtonColumn HeaderText="Drop Ticket" Text="Drop" CommandName="Delete"
UniqueName="Drop" ConfirmText="Are you sure you want to drop this ticket?" ConfirmTitle="Drop Ticket" ConfirmDialogType="RadWindow">
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings>
<PopUpSettings Modal="True"></PopUpSettings>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
I usually run into this when a width value for each column that does not add up to the width value of the RadGrid or leaving width values out altogether..
Try entering width values for each column but leave out the width value for the one column that would usually be the longest. In this case, I would choose the Title column.
Got it, turns out I was setting the ColumnSpan to an arbitrary number, 2 in this case, in the code-behind where the RadGrid is generated and it was causing that additional space to appear at the end. I was doing this to test another issue that has since been resolved. The snippet of code that was causing this is as follows and is commented out in my code now.
footerItem.Cells(2).ColumnSpan = 2

How can I pass along the Page Number in a HyperLinkField in a GridView?

I have gridview that I am using paging on. I want to pass along the current page in a asp:Hyperlink so I can send them back to the current page when they are done viewing the details of a record. Is this possible? If it is how can I do this?
<asp:GridView ID="grdObitList" runat="server" allowpaging="true"
PageSize="10" AutoGenerateColumns="false" CssClass="grdClass"
BorderStyle="None" GridLines="None" CellSpacing="2" >
<PagerStyle HorizontalAlign="Center" />
<PagerSettings Position="Bottom" FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast" />
<Columns>
<asp:HyperLinkField HeaderText="Name" DataTextField="obit_fullname" DataNavigateUrlFields="obit_id" DataNavigateUrlFormatString="obitDisplay.aspx?oid={0}" />
<asp:BoundField ReadOnly="true" HeaderText="Date" DataField="obit_dod" DataFormatString="{0:d/M/yyyy}" />
<asp:BoundField ReadOnly="true" HeaderText="Resident Of" DataField="obit_resident" />
<asp:BoundField ReadOnly="true" HeaderText="Funeral Home" DataField="obit_funeralhome" />
</Columns>
One way to do it is converting it to a template column, that way you can use normal databind syntaxt to get to it (<%#)

Resources