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>
Related
I am using Visual Studio 2015 and Entity Framework 6. I have a gridview displaying orders from a database. However, I need a user to be able to click a row and be taken to another page for editing that row after a dialog box confirmation.
This is what I have:
<asp:GridView ID="gridOrders" runat="server" Height="184px" Width="1359px" AutoGenerateColumns="false"
AllowSorting="true" >
<HeaderStyle Font-Bold="true" Font-Size="16pt" BackColor="#cc0000" ForeColor="Black" />
<RowStyle Font-Size="12pt" BackColor="#afadad" ForeColor="White"/>
<AlternatingRowStyle BackColor="#afadad" ForeColor="White" />
<Columns>
<asp:CommandField HeaderText="" SelectText="CANCEL ORDER" ShowSelectButton="true" ControlStyle-ForeColor="White" />
<asp:BoundField HeaderText="First Name" DataField="FirstName" SortExpression="FirstName" />
How do I make the row selection to another page happen with a dialog that asks user if they are sure?
Change your aspx page with the below code
<asp:GridView ID="gridOrders" runat="server" Height="184px" Width="1359px" AutoGenerateColumns="False"
AllowSorting="True">
<HeaderStyle Font-Bold="true" Font-Size="16pt" BackColor="#cc0000" ForeColor="Black" />
<RowStyle Font-Size="12pt" BackColor="#afadad" ForeColor="White" />
<AlternatingRowStyle BackColor="#afadad" ForeColor="White" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lnkCancelOrder" runat="server" OnClientClick="return confirm('Are you sure to redirect?')" OnClick="lnkCancelOrder_Click" CausesValidation="False" CommandArgument='<%#Eval("OrderID") %>' CommandName="Select" Text="CANCEL ORDER"></asp:LinkButton>
</ItemTemplate>
<ControlStyle ForeColor="White" />
</asp:TemplateField>
<asp:BoundField HeaderText="First Name" DataField="FirstName" SortExpression="FirstName" />
</Columns>
</asp:GridView>
Write the c# code as follows
You can redirect to another page and pass the orderID as QueryString, and retrieve the complete order information by orderID and show that in an edit mode form
protected void lnkCancelOrder_Click(object sender, EventArgs e)
{
LinkButton lnk = sender as LinkButton;
string orderID = lnk.CommandArgument;
Response.Redirect("AnotherPage.aspx?orderId="+orderID);
}
Write under the <asp:TemplateField> of Gridview as
<asp:LinkButton ID="anchrTag" runat="server" PostBackUrl="Your edit page url" OnClientClick="return confirm('Are u sure to leave this page and want to go for edit?');">Edit</asp:LinkButton>
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.
I have a grid on my aspx page.I have set its font property to small..
On page load it is all okay..
but once I perform some action like a delete activity given in the grid itself..and the grid is bound again by recalling the method to bind grid..
the grid seems to be bigger with big fonts.
What could be the trouble?
<asp:GridView ID="grdSMEList" runat="server" Width="100%" BorderWidth="1px" BorderStyle="Solid"
Font-Size="Small" AutoGenerateColumns="False" BorderColor="#ffcc00" RowStyle-BorderColor="#ffcc00"
AllowPaging="true" PageSize="10" OnPageIndexChanging="GrdDynamic_PageIndexChanging"
DataKeyNames="Resource Personnel No" OnRowCommand="GrdDynamic_RowCommand" RowStyle-BorderStyle="Solid"
RowStyle-BorderWidth="1px" GridLines="Both" Height="104px">
<PagerSettings NextPageText=">>" PageButtonCount="5" PreviousPageText="<<"
FirstPageText="" LastPageText="" Mode="Numeric" />
<PagerStyle HorizontalAlign="Right" Font-Size="Medium" />
<Columns>
<asp:BoundField DataField="Resource Personnel No" HeaderText="Resource Personnel No" ItemStyle-Width="100px" />
<asp:BoundField DataField="RES Name" HeaderText="ResourceName" ItemStyle-Width="100px" />
<asp:TemplateField HeaderText="Deactivate" >
<ItemTemplate>
<div style="text-align:center;">
<asp:LinkButton ID="linkDeactivate" CommandName="cmdDeactivate" OnRowCommand="GrdDynamic_RowCommand"
CommandArgument='<%# Eval("Resource Personnel No") %>' OnClientClick="return confirm('Are you sure you want to Deactivate?');"
runat="server">Deactivate</asp:LinkButton>
</div>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="2%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Did you try specifying the font color in ItemTemplate ? Its worth a try.
I'm using a gridview in asp.net. The gridview display heading is too large when it has one row.
But if it has pagination, it displays heading normally. I don't have any idea why.
Any help would be appreciated.
<asp:Panel ID="Panel2" runat="server" Height="310px" Width="100%" CssClass="mPanel" BorderStyle ="Groove">
<asp:GridView ID="gridViewResults" runat="server" Width = "100%"
AllowPaging = "true" OnPageIndexChanging="gridViewResults_PageIndexChanging"
CssClass="mGrid" OnSelectedIndexChanged="gridViewResults_SelectedIndexChanged"
Height="300px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" OnCheckedChanged="chkSelect_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
this is my code and iam binding it thru databasee..
First try this
<HeaderStyle Width="10%" />
<RowStyle Width="10%" />
If not work than do it from code side for all your colums after binding the gridview
int cou = gdv.Columns.Count;
for (int i = 0; i < cou; i++)
{
gdvProReq.Columns[i].HeaderStyle.Width = 50;
gdvProReq.Columns[i].ItemStyle.Width = 50;
}
The GridView will by default automatically size its columns to fit the largest row... when you paginate, the large row that was stretching out the headers was probably moved to one of the later pages.
You can manually size the columns to avoid the headers from dynamically resizing:
<Columns>
<asp:BoundField DataField="" HeaderText="" ItemStyle-Width="5%" />
<asp:BoundField DataField="" HeaderText="" ItemStyle-Width="25%" />
<asp:BoundField DataField="" HeaderText="" ItemStyle-Width="30%" />
<asp:BoundField DataField="" HeaderText="" ItemStyle-Width="25%" />
<asp:BoundField DataField="" HeaderText="" ItemStyle-Width="10%" />
</Columns>
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 (<%#)