We recently bought Asp.net Ajax control. We are migrating to asp.net grid ti radgrid. In my grid I ma editing and updating my rows. When I am trying to implement that in radgrid I am getting too many errors. Can any one help me how to do that? In which command i need to write the code???
What i want is once i edit the radgrid, i just want to catch the text in the textbox after i edited it. See the modified question above.
the above functionality i did in gridview as follows. But i dont know how to do it radgrid.
protected void gvCktMap_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
if (Session["TaskID"] != null)
{
string strTaskID = (string)Session["TaskID"];
if (strTaskID != string.Empty)
{
bool bolStatus = false;
clsTaskUpdates_BL objBL = new clsTaskUpdates_BL();
Label lblOrdID = (Label)gvCktMap.Rows[e.RowIndex].FindControl("lblorderId");
string strOrdId = lblOrdID.Text;
DataSet dsStatus = objBL.getTaskStatus_BL(lblOrdID.Text.Trim(), strTaskID.Trim());
if (dsStatus.Tables[0].Rows.Count > 0)
{
if (dsStatus.Tables[0].Rows[0][0].ToString() == "3" || dsStatus.Tables[0].Rows[0][0].ToString() == "4")
bolStatus = true;
}
if (!bolStatus)
{
Session["SearchRes"] = null;
if (strTaskID == "200")
{
TextBox txtClarifyID = (TextBox)gvCktMap.Rows[e.RowIndex].FindControl("txtClarifyAccountNbr");
TextBox txtSiteID = (TextBox)gvCktMap.Rows[e.RowIndex].FindControl("txtSiteID");
TextBox txtQuoteID = (TextBox)gvCktMap.Rows[e.RowIndex].FindControl("txtQuoteID");
CheckBox chkEDP = (CheckBox)gvCktMap.Rows[e.RowIndex].FindControl("chkEditEDPCreated?");
objBL.setTask200_Bl(lblOrdID.Text, txtClarifyID.Text, txtSiteID.Text, txtQuoteID.Text, chkEDP.Checked);
gvCktMap.EditIndex = -1;
bingGrid();
}
else if (strTaskID == "206")
{
TextBox txtConfigGenDate = (TextBox)gvCktMap.Rows[e.RowIndex].FindControl("txtConfigGenDate");
objBL.setTask206_Bl(lblOrdID.Text, txtConfigGenDate.Text);
gvCktMap.EditIndex = -1;
bingGrid();
}
else if (strTaskID == "207")
{
TextBox txtCPEShipDate = (TextBox)gvCktMap.Rows[e.RowIndex].FindControl("txtCPEShipDate");
TextBox txtPackageSlip = (TextBox)gvCktMap.Rows[e.RowIndex].FindControl("txtPackageSlip");
objBL.setTask207_Bl(lblOrdID.Text, txtCPEShipDate.Text.Trim(), txtPackageSlip.Text.Trim());
gvCktMap.EditIndex = -1;
bingGrid();
}
else if (strTaskID == "208")
{
TextBox txtCORECMNumber = (TextBox)gvCktMap.Rows[e.RowIndex].FindControl("txtCORECMNumber");
TextBox txtReqSMImpDate = (TextBox)gvCktMap.Rows[e.RowIndex].FindControl("txtReqSMImpDate");
objBL.setTask208_Bl(lblOrdID.Text, txtReqSMImpDate.Text.Trim(), txtCORECMNumber.Text.Trim());
gvCktMap.EditIndex = -1;
bingGrid();
}
}
else
{
// ScriptManager.RegisterClientScriptBlock(this.up, this.GetType(), "updateMsg", "<script>alert('The task has been completed by '" + dsStatus.Tables[0].Rows[0]["tskCompletedBy"].ToString() + " + '. Refresh the task list using F5')</script>", false);
ScriptManager.RegisterClientScriptBlock(this.up,up.GetType(), "updateMsg", "fnStatusMsg()", true);
gvCktMap.EditIndex = -1;
bingGrid();
}
}
}
}
catch (Exception ex)
{
}
}
my radgrid aspx file code
<telerik:RadGrid ID="rg200" runat="server" AutoGenerateColumns="False" PageSize="30"
Height="550px" OnNeedDataSource="rg200_NeedDataSource" Width="100%" AllowPaging="True"
AllowSorting="True" AllowMultiRowSelection="True" EnableHeaderContextMenu="True"
GridLines="None" EnableHeaderContextFilterMenu="True" AllowMultiRowEdit="True"
AllowFilteringByColumn="True" OnPreRender="rg200_PreRender" OnItemCreated="rg200_ItemCreated"
EnableViewState="False" OnUpdateCommand="rg200_UpdateCommand">
<HeaderStyle Height="20px" BackColor="#004000" Font-Size="8pt" Font-Bold="True" ForeColor="White"
HorizontalAlign="Center" BorderColor="White" BorderWidth="1px" />
<ExportSettings IgnorePaging="true" ExportOnlyData="true">
<Pdf AllowModify="false" AllowPrinting="true" PageBottomMargin="" PageFooterMargin=""
PageHeaderMargin="" PageHeight="11in" PageLeftMargin="" PageRightMargin="" PageTopMargin=""
PageWidth="14in" />
</ExportSettings>
<MasterTableView DataKeyNames="orderId" CommandItemDisplay="Top" EditMode="InPlace">
<CommandItemSettings ShowExportToWordButton="true" ShowExportToExcelButton="true"
ShowExportToCsvButton="true" ShowExportToPdfButton="true" ShowAddNewRecordButton="false" />
<RowIndicatorColumn Visible="True">
</RowIndicatorColumn>
<Columns>
<telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" HeaderStyle-Width="3%"
ItemStyle-Width="3%">
<HeaderStyle Width="3%"></HeaderStyle>
<ItemStyle Width="3%"></ItemStyle>
</telerik:GridClientSelectColumn>
<telerik:GridBoundColumn UniqueName="sId" HeaderText="sId" DataField="sId" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="orderId" HeaderText="orderId" DataField="orderId"
Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Customer Name" HeaderText="Customer Name" DataField="Customer Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Market Name" HeaderText="Market Name" DataField="Market Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="LOB" HeaderText="LOB" DataField="LOB" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Headend Name" HeaderText="Headend Name" DataField="Headend Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Project Name" HeaderText="Project Name" DataField="Project Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Site Name" HeaderText="Site Name" DataField="Site Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Task Status" HeaderText="Task Status" DataField="Task Status"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="Clarify Account Nbr" HeaderText="Clarify Account Nbr"
DataField="Clarify Account Nbr">
<ItemTemplate>
<asp:Label ID="lblClarifyAccountNbr" Text='<%# Eval("Clarify Account Nbr") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtClarifyAccountNbr" Text='<%# Eval("Clarify Account Nbr") %>'
runat="server"></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<%-- <telerik:GridBoundColumn UniqueName="Clarify Account Nbr" HeaderText="Clarify Account Nbr"
DataField="Clarify Account Nbr">
</telerik:GridBoundColumn>--%>
<telerik:GridBoundColumn UniqueName="Site ID" HeaderText="Site ID" DataField="Site ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Quote ID" HeaderText="Quote ID" DataField="Quote ID">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn UniqueName="EDP Created?" HeaderText="EDP Created?" DataField="EDP Created?">
</telerik:GridCheckBoxColumn>
<telerik:GridEditCommandColumn UniqueName="ECC200">
</telerik:GridEditCommandColumn>
</Columns>
<PagerStyle AlwaysVisible="True"></PagerStyle>
</MasterTableView>
</telerik:RadGrid>
Start with the demos available on Telerik's site, and work from there.
Or, rebuild your grid from scratch using the radgrid.
What you've posted is not helpful at all. It's a wall of text with no direction as to any sort of specific error. We're not mind readers here.
Related
I am having a problem getting the values from the Radgrid auto generated Insert form.
I have my radgrid setup as shown in code shown below. I am only doing inserts and deletes and am using the edit form that is automatically opened when I click the add new record button.
<div id ="specialrequestGrid" class="container">
<div class="row">
<div class="col-md-12">
<telerik:RadAjaxPanel runat="server">
<telerik:RadGrid ID="SpecialRequests" runat="server" OnInsertCommand="SpecialRequests_InsertCommand"
OnUpdateCommand="SpecialRequests_UpdateCommand"
OnItemCommand="SpecialRequests_ItemCommand"
AllowAutomaticInserts="false"
AutoGenerateColumns="false"
OnNeedDataSource="SpecialRequests_NeedDataSource">
<MasterTableView CommandItemDisplay="Top" DataKeyNames="CaseId_FK, ReqId" Font-Size="Medium" NoMasterRecordsText="No Special Requests">
<CommandItemSettings AddNewRecordImageUrl="../Images/Add.png" />
<Columns>
<telerik:GridTemplateColumn HeaderText="Request Date" UniqueName="DateTemplateColumn">
<ItemTemplate>
<asp:Label ID="DateEditItemTemplate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Date","{0:MM/dd/yyyy}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="dpRideDate" runat="server" DateInput-DateFormat="MM/dd/yyyy" DbSelectedDate='<%# Bind("Date") %>' MinDate="1999/1/1" UniqueName="dpRideDate">
</telerik:RadDatePicker>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Requested By ID" UniqueName="RequestorTemplateColumn">
<ItemTemplate>
<asp:Label ID="Requestor" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "RequesterEID_FK") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<button id="btnRequestEID" type="button" class="btn" data-toggle="modal" data-target="#myModal" >--Please Select--</button>
<div>
<input type="text" Id="TxtSPRequestName" disabled />
</div>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Request Reason" UniqueName="RequestReason">
<ItemTemplate>
<asp:Label ID="ItemTemplatelblRequestReason" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Reason") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblRequestReason" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Reason") %>' Visible="false">
</asp:Label>
<asp:TextBox runat="server" ID="txtReason" Text='<%# DataBinder.Eval(Container.DataItem, "Reason") %>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridCheckBoxColumn DataField="IsWOO" HeaderText="Is Out of Order" UniqueName="ISWOO"></telerik:GridCheckBoxColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
</div>
</div>
</div>
This is the screenshot of the auto generated form I get when I click the add new record
When I click the Insert link on the form I run this C# code
protected void SpecialRequests_InsertCommand(object sender, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
T_SpecialRequests t = new T_SpecialRequests();
t.IsWOO = (userControl.FindControl("IsWOO") as CheckBox).Checked;
}
Note the IsWOO is a control in the Radgrid that I did not show in the Screenshot. When I click the save link the Insert Function, shown above Runs but I get the following error:
Unhandled exception at line 1, column 123034 in http://localhost:52028/bundles/MsAjaxJs?v=c42ygB2U07n37m_Sfa8ZbLGVu4Rr2gsBo7MvUEnJeZ81
0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
The strange part is I use this same code in several other projects without any problems. The only difference is this is the first time I have used this auto generated form. I don't want to use the another type of control for this Radgrid due to such a small number of fields, only have 4 control.
I have spent several hours searching for an answer but just can't find the solution.
How can I get the values from this auto generated form?
You can use
t.IsWOO = (editedItem["ISWOO"].Controls[0] as CheckBox).Checked;
or
var newValues = new Dictionary<string, object>();
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
t.IsWOO = (bool)newValues["IsWOO"];
The first approach references the control by index because unfortunately it has no ID.
The second one is a bit verbose for just one property but I would surely prefer it if there were more properties.
While #Michal Nawrocik was correct I found that I still had some problems reading all of the controls in the Radgrid. I was able to track down the answer on the Telerik forum and found that you have to use different code based on the Column Type. I had 2 different type of columns.
the code below shows what I used to get all of the control values on the form
protected void SpecialRequests_InsertCommand(object sender, GridCommandEventArgs e)
{
try
{
using(LatentEntities db = new LatentEntities())
{
if (e.Item is GridEditableItem)
{
T_SpecialRequests T = new T_SpecialRequests();
var editableItem = ((GridEditableItem)e.Item);
RadDatePicker picker = (RadDatePicker)editableItem.FindControl("dpDate"); // in EditItem Template
DateTime dt = Convert.ToDateTime(picker.DbSelectedDate);
T.Date = dt;
TextBox Reason = (TextBox)editableItem.FindControl("txtReason"); //This Control was in an Edit Item Template
T.Reason = Reason.Text;
T.IsWOO = (editableItem["ISWOO"].Controls[0] as CheckBox).Checked; //In CheckBox Column
}
}
And if the control is in a Telerik:GridtboundColumn I used this code:
string strFirstName = (editableItem["firstname"].Controls[0] as TextBox).Text;
I am trying to add RadCombobox to a telerik:GridTemplateColumn as a FilterTemplate control. I have multiple columns and all have RadCombobox with same filter values.
<telerik:GridTemplateColumn AutoPostBackOnFilter="true" HeaderStyle-Width="90px"
UniqueName="Date1" HeaderText="Date1" DataField="Day1">
<FilterTemplate>
<telerik:RadComboBox ID="RadComboBoxDate1" Height="90px" AppendDataBoundItems="true"
Width="105px" runat="server" OnClientSelectedIndexChanged="Date1IndexChanged">
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function Date1IndexChanged(sender, args) {
var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");
var selectedValue = sender.get_value();
if (selectedValue) {
if (parseInt(selectedValue) < 0) {
tableView.filter("Date1", selectedValue, "NoFilter");
}
else { tableView.filter("Date1", selectedValue, "EqualTo");
}
}
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
<ItemTemplate>
<asp:Label runat="server" ID="lblday1"></asp:Label>
<asp:HiddenField ID="hdDay1" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"Day1") %>' Visible="false" />
</ItemTemplate>
</telerik:GridTemplateColumn>
I have 7 such columns and I want to use a single RadCodeBlock to handle the filter. Is there any better way to do this?
Solution given on Telerik website worked for me
http://www.telerik.com/forums/how-to-get-column-name-from-filter-template-control-s-js-event
Good day,
I have a GridTemplateColumn with a RadTextbox. The textbox values are changed by javascript. But when i click the textbox,it changes back to its original value.
Please help
javascript
<title>Untitled Page</title>
<script type="text/javascript">
function changeCountry() {
var grid = $find('<%=RadGrid1.ClientID %>');
var MasterTable = grid.get_masterTableView();
var dataItems = MasterTable.get_dataItems();
var cellCountry = dataItems[0].get_cell("CountryCol");
var txtCountry = $telerik.$(cellCountry).find('input')[0];
txtCountry.value = "New Country";
}
</script>
.aspx
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" CellSpacing="0" GridLines="None" PageSize="20" AutoGenerateColumns="false" OnItemDataBound="RadGrid1_ItemDataBound">
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<ClientSettings>
<Selecting CellSelectionMode="None" AllowRowSelect="True" />
</ClientSettings>
<MasterTableView>
<CommandItemSettings ExportToPdfText="Export to PDF" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="CR_Branch" HeaderText="Branch"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CR_Country" HeaderText="Branch" Display=false></telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="CR_Country" DataField="CR_Country" UniqueName="CountryCol">
<ItemTemplate>
<telerik:RadTextBox ID="txtCountry" runat="server"></telerik:RadTextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
.aspx.cs
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridHeaderItem)
{
}
if (e.Item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;
RadTextBox txtCountry = ((RadTextBox)dataItem.FindControl("txtCountry"));
txtCountry.Text = dataItem["CR_Country"].Text;
}
}
You need to use the Telerik client script set_value function rather than pure javascript/HTML, i.e.
function changeCountry() {
var grid = $find('<%=RadGrid1.ClientID %>');
var MasterTable = grid.get_masterTableView();
var dataItems = MasterTable.get_dataItems();
dataItems[0].findControl("txtCountry").set_value("New Country");
}
I am working on extending an ASP.NET 2.0 application using an InterBase database. My experience is in PHP/MySQL, so my familiarity with ASP is currently in the 2-week range, and is pieced together from examining a co-worker's code, the first 90 pages of my ASP book, and Google. In the application, I have an SqlDataSource control connecting to my database and selecting the information I need. Then the results are copied into a DataView where I modify the data in one of the columns, and then I push that DataView to a GridView for output. The issue I'm having is that I cannot sort the GridView at this point. I followed instructions here: http://forums.asp.net/p/956540/1177923.aspx, but to no avail.
Here is the page code:
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="Products" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>" OnLoad="ProductsDS_Load"
OnSelected="ProductsDS_Selected" DataSourceMode="DataSet">
</asp:SqlDataSource>
<br />
<asp:Label ID="testlabel" runat="server"></asp:Label>
<br />
<asp:Label ID="testlabel2" runat="server"></asp:Label>
<br /><br />
This table lists all 2000+ numbered projects which are at least partially in process.<br />
The Project number link leads to a more detailed view of that project.<br />
<br />
<asp:Label runat="server" ID="numrows"></asp:Label> results returned.
<br />
<asp:GridView ID="ProductsView" runat="server" EnableModelValidation="True"
AutoGenerateColumns="False" CellPadding="4" OnSorting="ProductsView_Sorting"
ForeColor="#333333" GridLines="None" AllowSorting="True">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:HyperLinkField HeaderText="Project" SortExpression="PROJECT"
DataTextField="PROJECT" Target="subweeklyreport" DataNavigateUrlFields="PROJECT"
DataNavigateUrlFormatString="Products.aspx?p={0}" />
<asp:BoundField Visible="false" DataField="PROJECTID" />
<asp:BoundField DataField="PART" HeaderText="Part #"
SortExpression="PART" />
<asp:BoundField DataField="DESCRIPTION" HeaderText="Description"
SortExpression="DESCRIPTION" />
<asp:BoundField DataField="ENGMGR" HeaderText="Eng. Mgr."
SortExpression="ENGMGR" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</div>
</form>
And here is the code behind:
protected void ProductsDS_Load(object sender, EventArgs e)
{
string SQLQuery = Query would go here;
testlabel2.Text = SQLQuery;
Products.SelectCommand = SQLQuery;
Products.DataBind();
DataView dv = (DataView)Products.Select(new DataSourceSelectArguments());
foreach (DataRow dr in dv.Table.Rows)
{
string name = dr["ENGMGR"].ToString();
string[] explode = name.Split(' ');
string newname;
if (explode.Length == 3)
{
newname = explode[2] + ", " + explode[0];
}
else
{
newname = explode[1] + ", " + explode[0];
}
dr["ENGMGR"] = newname;
//testlabel.Text = dr["ENGMGR"].ToString();
}
Products.DataBind();
//ProductsView.DataSourceID = "Products";
ProductsView.DataSource = dv;
ProductsView.DataBind();
ProductsView.Enabled = true;
ProductsView.Visible = true;
}
protected void ProductsDS_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
numrows.Text = e.AffectedRows.ToString();
}
protected void ProductsView_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = ProductsView.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
ProductsView.DataSource = dataView;
ProductsView.DataBind();
}
}
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}
What I think is happening is that whenever the GridView does the postback for the sort, it causes the query to be executed again and overwrite the attempt to sort the existing data in the GridView, but I don't know enough about ASP right now to prevent this behavior. Any help would be much appreciated.
I ended up solving my own problem. I created a session variable to store the dataview between page loads, and checking to see if the dataview is stored before executing the query, and sorting it if it is, and just performing the regular query otherwise. Since I don't expect data to be introduced between the initial page view and the sort, I don't think using a stored copy of the data would be a major issue.
I am using RadGrid with rowcontextmenu. When I right click on a RadGrid row and select 'edit option' it will open a popup window.
What I need is when I right click on a Radgrid row, I just want to get the values of 3 columns for that particular selected row. For example, when I right click on a selected Radgrid row I want to get Customer name, Headend name, Site name values of that selected row.
Here is my code:
<MasterTableView GridLines = "None" DataKeyNames="orderId" CommandItemDisplay="Top"
EditMode="EditForms">
<Columns>
<telerik:GridClientSelectColumn UniqueName = "ClientSelectColumn" HeaderStyle-Width="3%"
ItemStyle-Width="3%">
<HeaderStyle Width = "3%" ></ HeaderStyle >
<ItemStyle Width="3%"></ItemStyle>
</telerik:GridClientSelectColumn>
<telerik:GridBoundColumn UniqueName = "sId" HeaderText="sId" DataField="sId" ReadOnly="true"
Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "orderId" HeaderText="orderId" Visible="false"
ReadOnly="true" DataField="orderId">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Customer Name" HeaderText="Customer Name" DataField="Customer Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Market Name" HeaderText="Market Name" DataField="Market Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "LOB" HeaderText="LOB" DataField="LOB" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Headend Name" HeaderText="Headend Name" DataField="Headend Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Project Name" HeaderText="Project Name" DataField="Project Name"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName = "Site Name" HeaderText="Site Name" DataField="SiteName"
ReadOnly="true">
<ItemTemplate>
<asp:LinkButton ID = "lnkSiteName" runat="server" Text='<%# Eval( "Site Name" ) %>'
ForeColor="Blue" CommandName="sitename"></asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName = "Task Status" HeaderText="Task Status" DataField="Task Status"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Clarify Account Nbr" HeaderText="Clarify Account Nbr"
DataField="Clarify Account Nbr">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Site ID" HeaderText="Site ID" DataField="Site ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName = "Quote ID" HeaderText="Quote ID" DataField="Quote ID">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn UniqueName = "EDP Created?" HeaderText="EDP Created?" DataField="EDP Created?">
</telerik:GridCheckBoxColumn>
<telerik:GridEditCommandColumn UniqueName = "EditCommandColumn" Display="false">
</telerik:GridEditCommandColumn>
</Columns>
</Mastertableview>
protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e)
{
int radGridClickedRowIndex;
radGridClickedRowIndex = Convert.ToInt32(Request.Form["radGridClickedRowIndex"]);
switch (e.Item.Text)
{
case "Edit Task":
string OrdID = rg200.MasterTableView.DataKeyValues[radGridClickedRowIndex]["orderId"].ToString();
lblOrdHeadName.Text = rg200.MasterTableView.NamingContainer.FindControl("Headend Name").ToString();
Session["orderId"] = OrdID;
ifrmPopups.Style.Add("height", "409px");
StringBuilder Script = new StringBuilder();
Script.Append("document.getElementById('ctl00_PagePlaceholder_WinEditForm_C_ifrmPopups');openpopups()");
RadAjaxManager1.ResponseScripts.Add(Script.ToString());
rg200.Rebind();
break;
}
}
If you see the above code, I am able to get the orderId value for that selected column. But when I am trying to get Headend Name value I am getting an error. How to get the Headend Name value for selected row?
Try the following. It worked for me.
GridDataItem item =(GridDataItem)rg200.MasterTableView.Items[rg200.SelectedItems[0].ItemIndex];
lblOrdHeadName.Text = item["HeadendName"].Text;
You can use the following code to loop through the selected items and store the ID values into an array and thereby pass it to a method. Also set the EnablePostBackOnRowClick property of the grid to true
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
string[] array = new string[10];
int i = 0;
if (e.CommandName == "RowClick")
{
foreach (GridDataItem item in RadGrid1.SelectedItems)
{
array[i] = item.GetDataKeyValue("EmpID").ToString(); // storing to array
i++;
}
}
}
Try out this code to get the Headend Name value from the right-clicked row:
lblOrdHeadName.Text = (rg200.MasterTableView.FindItemByKeyValue("orderId") as GridDataItem)["Headend Name"].Text;
I found the solution:
GridDataItem item = (GridDataItem)rg200.MasterTableView.Items[radGridClickedRowIndex];
lblOrdHeadName.Text = item["HeadendName"].Text;