I have a radgrid populated with data in double click I launch a rad window manager with texbox that need to fill with the data selected on the radgrid. I fail to get the value of the row. I can only get the index of the selected item.
this is my grid aspx:
<telerik:RadGrid ID="rgBuscar" runat="server" CellSpacing="0" Culture="es-ES"
GridLines="None" Height="469px" Skin="Hay" Width="944px">
<ClientSettings>
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<MasterTableView>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowDblClick="RowDblClick"/>
</ClientSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
<FilterMenu EnableImageSprites="False"></FilterMenu>
and my JS:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function RowDblClick(sender, args) {
var index = args.get_itemIndexHierarchical();
sender.get_masterTableView().fireCommand("RowDblClick", index);
}
</script>
and finally my VB:
Protected Sub rgBuscar_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgBuscar.ItemCommand
If e.CommandName = "RowDblClick" Then
Dim var As String = e.CommandArgument
idValor = e.Item.Cells(2).Text
MostrarVentana(idValor)
End If
End Sub
Public Sub MostrarVentana(ByVal IdCampo As Integer)
lector = objBd.obtenerConfiguraciones("Cambio Ordenes")
While lector.Read
rwmCambio.Windows(0).NavigateUrl = lector("OCON_Url") & "?IdCampo=" & IdCampo
rwmCambio.Windows(0).Width = Unit.Pixel(lector("OCON_Width"))
rwmCambio.Windows(0).Height = Unit.Pixel(lector("OCON_Height"))
End While
rwmCambio.Windows(0).VisibleOnPageLoad = True
End Sub
Telerik provides a rich API for the RadGrid, by assigning a value to the DataKeyValues (or ClientDataKeyNamesif you want to access them using the Client API rather than posting back) attributes of the MasterTableView you can access the data related to the item through the code; to add multiple columns to the data key collection, separate the column names with a comma.
Example Data Key Definitions:
<MasterTableView DataKeyNames="idColumnName,foreignKeyColumnName" ClientDataKeyNames="idColumnName,anotherColumnName">
Example OnRowSelected event client-side (JavaScript) event handler:
function OnGridRowSelected(sender, args) {
var idDataKey = args.getDataKeyValue("idColumnName");
var nameDataKey = args.getDataKeyValue("idColumnName");
document.getElementById("myElement").value = "(" + idDataKey + ") " + nameDataKey;
}
Example ItemCommand event server-side (VB) event Handler:
Protected Sub PerformActionOnGridItem(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles grdCustomerAccountInvoiceSummary.ItemCommand
If (TypeOf (e.Item) Is Telerik.Web.UI.GridDataItem) Then
Dim item As Telerik.Web.UI.GridDataItem = CType(e.Item, Telerik.Web.UI.GridDataItem)
Select Case e.CommandName
Case "RowDblClick"
' Insert required code here
...
' Example: Set session variable to data key value
Session("idColumnName") = item.GetDataKeyValue("idColumnName")
End Select
End If
End Sub
Related
I have an ASPxGridView control that needs a button that is visible on a conditional basis. I have searched and read several articles but have not found a fix for my particular situation. The button is called btnAllocatePlan and it should only be displayed if the value in a column called PayPlanFlg is true. Below is the markup for the grid and two things I tried in the codebehind, which is where I'd rather do this. Actually neither of these events even fired. Any help is greatly appreciated!
<dx:ASPxGridView ID="grdPayments" runat="server" CssClass="tblLined" SettingsPager-PageSize="50"
AutoGenerateColumns="False" KeyFieldName="PaymentKey" Width="100%">
<SettingsBehavior AllowFocusedRow="True" ProcessFocusedRowChangedOnServer="True" />
<Columns>
<dx:GridViewDataTextColumn Caption="CaseKey" FieldName="CaseKey" Visible="False" VisibleIndex="0">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Name" FieldName="Name" VisibleIndex="1" Width="10%">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Association" FieldName="AssociationName" VisibleIndex="2" Width="15%">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Address" FieldName="Address1" VisibleIndex="3" Width="15%">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Amount Paid" FieldName="Amount" VisibleIndex="4" Width="5%">
<PropertiesTextEdit DisplayFormatString="c"></PropertiesTextEdit>
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Payment Date" FieldName="TransactionTime" VisibleIndex="5" Width="12%">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Payment Type" FieldName="PaymentType" VisibleIndex="6" Width="3%">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Amount Owed" FieldName="Balance" VisibleIndex="7" Width="5%">
<PropertiesTextEdit DisplayFormatString="c">
</PropertiesTextEdit>
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Amount Available" FieldName="AmountAvailable" VisibleIndex="8" Width="6%">
<PropertiesTextEdit DisplayFormatString="c">
</PropertiesTextEdit>
</dx:GridViewDataTextColumn>
<dx:GridViewDataHyperLinkColumn Name="AllocationLink" VisibleIndex="9" Caption=" " UnboundType="String" Width="5%">
<DataItemTemplate>
<!--<%#"Allocate"%>-->
<dx:ASPxButton ID="btnAllocate" runat="server" Text="Allocate" OnClick="btnAllocate_Click" />
</DataItemTemplate>
</dx:GridViewDataHyperLinkColumn>
<dx:GridViewDataHyperLinkColumn Name="PlanLink" VisibleIndex="10" Caption=" " UnboundType="String" Width="5%">
<DataItemTemplate>
<!--<%#"Allocate"%>-->
<dx:ASPxButton ID="btnAllocatePlan" runat="server" Text="Pay Plan" OnClick="btnAllocatePlan_Click" />
</DataItemTemplate>
</dx:GridViewDataHyperLinkColumn>
<dx:GridViewDataTextColumn Caption="PayPlanFlg" FieldName="PayPlanFlg" Visible="false" VisibleIndex="11">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
Codebehind attempts:
Protected Sub grdPayments_CustomButtonInitialize(sender As Object, e As ASPxGridViewCustomButtonEventArgs)
If e.Button.ID = "btnAllocatePlan" Then
If grdPayments.GetRowValues(e.VisibleIndex, 11, "PayPlanFlg") = 1 Then
e.Button.Visibility = GridViewCustomButtonVisibility.Invisible
End If
End If
End Sub
Protected Sub ASPxGridView1_HtmlDataCellPrepared(sender As Object, e As ASPxGridViewTableDataCellEventArgs)
If e.DataColumn.FieldName = "ID" Then
Dim textBox As ASPxButton = TryCast(ASPxGridView1.FindRowCellTemplateControl(e.VisibleIndex, e.DataColumn, "btn"), ASPxButton)
If Convert.ToString(e.GetValue("ItemName")).Equals("B") Then
textBox.Text = Convert.ToString(e.CellValue)
textBox.Visible = True
Else
textBox.Visible = False
End If
End If
End Sub
The best approach is to handle the Button's Init/Load event. This
recommended technique is described in the The general technique of
using the Init/Load event handler KB article.
Check below example code for hiding a particular button in a row..
aspx
<dx:GridViewDataHyperLinkColumn Name="AllocationLink" VisibleIndex="9" Caption=" " UnboundType="String" Width="5%">
<DataItemTemplate>
<!--<%#"Allocate"%>-->
<dx:ASPxButton ID="btnAllocate" runat="server" Text="Allocate" OnInit="btnAllocate_Init" />
</DataItemTemplate>
</dx:GridViewDataHyperLinkColumn>
.cs
protected void btnAllocate_Init(object sender, EventArgs e)
{
DevExpress.Web.ASPxButton btn = (DevExpress.Web.ASPxButton)sender;
GridViewDataItemTemplateContainer container = btn.NamingContainer as GridViewDataItemTemplateContainer;
// You can remove the if statement, and try to insert a new record. You'll catch an exception, because the DataBinder returns null reference
if (container != null && !container.Grid.IsNewRowEditing)
btn.Visible = !(bool)DataBinder.Eval(container.DataItem, "PayPlanFlg");
}
Reference:
ASPxGridView - Hide the control in the DataItemTemplate conditionally
I really have no idea.
I am trying to return a view with results from a Joined Table.
I keep receiving this error:
"The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery`1[System.String[]]', but this dictionary requires a model item of type 'tacticMVC.crypto'. "
my controller code is as follows
Function Details(Optional ByVal id As Integer = Nothing) As ActionResult
If Request.IsAuthenticated = True Then
'Dim cryptoes = db.cryptoes.Where(Function(c) c.key_email = HttpContext.User.Identity.Name()).ToList()
'Dim crypto As crypto = db.cryptoes.Find(cryptoes(0).id_cypto)
Dim crypto = (From c In db.cryptoes
Join con In db.consumers On c.id_consumer Equals con.id_consumer
Where c.id_consumer = 3
Select {c.key_email})
Return View(crypto)
Else
Return HttpNotFound()
End If
End Function
If I use just the 2 commented lines in the function the view returns fine but of course I can only get the data from one table. I need to join the tables and then return the data.
I've tried adding .toList(), .singleordefault() etc - does not solve anything
the vbhtml file:
#ModelType tacticMVC.crypto
<h2>Details</h2>
#Using Html.BeginForm("Action", "Controller", FormMethod.Post)
#<fieldset>
<div class="display-label">
#Html.DisplayNameFor(Function(model) model.key_email)
</div>
<div class="display-field">
#Html.DisplayFor(Function(model) model.key_email)
something
</div>
</fieldset>
#<p>
#Html.ActionLink("Edit", "Edit", New With {.id = Model.id_cypto}) |
#Html.ActionLink("Back to List", "Index")
</p>
End Using
You're returning a database query object directly, but your page's cshtml says it expects a typed ViewModel.
Where is tacticMVC.crypto defined and what does it look like?
Dim crypto does not mean "an object of type crypto", it means "A late-bound object named crypto".
Great! - Just like a lot of other experiences after spending hours on it I have worked it out immediately after I posted my question.
Answer:
Controller
Function Details(Optional ByVal id As Integer = Nothing) As ActionResult
If Request.IsAuthenticated = True Then
Dim cryptoes = db.cryptoes.Where(Function(c) c.key_email = HttpContext.User.Identity.Name()).ToList()
Dim crypto As crypto = db.cryptoes.Find(cryptoes(0).id_cypto)
Return View(crypto)
Else
Return HttpNotFound()
End If
End Function
vbhtml
<div class="display-field">
#Html.DisplayFor(Function(model) model.consumer.name_consumer)
</div>
I am open to a better solution
Thanks
I have a Radgrid and I bind it with SqlAdapter. My problem is that I want to change just one column's value. Is that possible?
My column name is IsShadow and it binds true or false. I cannot change it. If value is false or true, I change column text appearence, not database update.
Code I've tried
foreach (Telerik.Web.UI.GridDataItem dataItem in gridShadow.MasterTableView.Items)
{
bool flag = Convert.ToBoolean(dataItem.GetDataKeyValue("IsShadow"));
GridEditableItem editedItem = dataItem as GridEditableItem;
if (!flag)
{
TableCell tableCell = editedItem["IsShadow"] = ???
}
}
Thank you.
Please try with the below code snippet and let me know if any concern.
// Normal Mode
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
item["IsShadow"].Text = "Your new text";
}
// Edit Mode
if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
{
GridEditableItem editItem = (GridEditableItem)e.Item;
(editItem["IsShadow"].Controls[0] as TextBox).Text = "Your new text";
}
You probably need a GridTemplateColumn
In the ItemTemplate you will check the value of IsShadow and display some text, but in EditItemTemplate you would probably need to just have a checkbox for true/false.
<telerik:GridTemplateColumn HeaderText="Is Shadow" UniqueName="TemplateColumn">
<EditItemTemplate>
<asp:CheckBox id="editChkBox" runat="server"
Checked='<%# Bind("IsShadow") %>'>
</asp:CheckBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Lable id="lblIsShadow" runat="server"
Text='<%# Convert.ToBoolean(Eval("IsShadow")) == true ? "it is shadow" : "Not shadow" %>'>
</asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
Iam doing XML reading using dom concepts, But i couldn't retrieve values correctly.
I want to RETRIEVE BELOW PART using for loop statement
<area id="508" Type="paragraph" visible="1" source_ap="True" invert="False" rotation="0" ignoretext="0">
<pagename><![CDATA[11187_2014_06_14_000002_0004_NFHEZ]]></pagename>
<pagenumber>1</pagenumber>
<left>603</left>
<top>868</top>
<right>764</right>
<bottom>1132</bottom>
<polygon ispolygon="0" noofpoints="0"><![CDATA[]]></polygon>
</area>
HERE IS THE FULL SAMPLE XML WHERE I WANT TO RETRIEVE USING FOR LOOP.
<?xml version="1.0" encoding="UTF-8"?>
<articles>
<template istemplate="true" twidth="0" theight="0" uwidth="0" uheight="0" ubottom="0"> </template>
<article name="11187_2014_06_14_000002_0004_NFHEZ_00004" id="4">
<articlename><![CDATA[11187_2014_06_14_000002_0004_NFHEZ_00004]]></articlename>
<input_pages>
<page name="11187_2014_06_14_000002_0004_NFHEZ" number="3">
<pagepdfheight>1125</pagepdfheight>
<pagepdfwidth>786</pagepdfwidth>
<pagejpgheight>1125</pagejpgheight>
<pagejpgwidth>786</pagejpgwidth>
<pagejpgresolution>72</pagejpgresolution>
<name><![CDATA[11187_2014_06_14_000002_0004_NFHEZ]]></name>
<Article_Area>0</Article_Area>
<Article_percentage>0</Article_percentage>
</page>
</input_pages>
<NoOfPage>1</NoOfPage>
<output_pages>
<page number="1" height="0" width="0"/>
</output_pages>
<read>
<area id="508" Type="paragraph" visible="1" source_ap="True" invert="False" rotation="0" ignoretext="0">
<pagename><![CDATA[11187_2014_06_14_000002_0004_NFHEZ]]></pagename>
<pagenumber>1</pagenumber>
<left>603</left>
<top>868</top>
<right>764</right>
<bottom>1132</bottom>
<polygon ispolygon="0" noofpoints="0"><![CDATA[]]></polygon>
</area>
<area id="507" Type="paragraph" visible="1" source_ap="True" invert="False" rotation="0" ignoretext="0">
<pagename><![CDATA[11187_2014_06_14_000002_0004_NFHEZ]]></pagename>
<pagenumber>1</pagenumber>
<left>462</left>
<top>868</top>
<right>601</right>
<bottom>1131</bottom>
<polygon ispolygon="0" noofpoints="0"><![CDATA[]]></polygon>
</area>
</read>
My code is:
Dim doc As New XmlDocument()
Dim sValue, sPgName As String
Dim sLeft, sTops, sRight, sBottom As String
Dim ObjZoneInfo As CZoneInfo
Try
doc.Load(sFile)
If doc.ChildNodes.Item(0).Name = "xml" Then
If doc.ChildNodes.Item(1).Name = "articles" Then
For i As Integer = 0 To doc.ChildNodes.Item(1).ChildNodes.Count - 1
If doc.ChildNodes.Item(2).ChildNodes.Item(i).Name = "article" Then
ObjZoneInfo = New CZoneInfo
For j As Integer = 0 To doc.ChildNodes.Item(2).ChildNodes.Item(i).ChildNodes.Count - 1
sValue = doc.ChildNodes.Item(1).ChildNodes.Item(i).ChildNodes.Item(j).InnerText
If doc.ChildNodes.Item(1).ChildNodes.Item(i).ChildNodes.Item(j).Name = "page_name" Then
If sProFiles.Contains(sValue) = False Then
sProFiles.Add(sValue)
End If
ObjZoneInfo.PageName = sValue : sPgName = sValue
I understand you are searching only for nodes with "area" tag, so try this:
Dim tagAreas as XmlNodeList = doc.GetElementsByTagName("area")
You can then use a For Each loop:
For Each tagArea as XmlElement in tagAreas Then
'______your code here. If you wanted to retrieve the "area" tag I don't understand the code you posted
Next
Now, to access attributes of the area nodes, you must use the following:
Dim area_id as Integer = Integer.parse(tagArea.GetAttribute("id")) 'if you want to obtain id data as integer
Dim area_type as String = tagArea.GetAttribute("type")
'so etc___________________
if you want to access the child nodes:
Dim area_pagenum as Integer = Integer.parse(tagArea("pagenumber"))
I'm having trouble with checkboxes on my site.
Here's the code I have so far:
#{
Layout = "~/_SiteLayout.cshtml";
WebSecurity.RequireAuthenticatedUser();
var db = Database.Open("StayInFlorida");
var rPropertyId = Request.QueryString["PropertyID"];
var Propertyinfo = "SELECT * FROM PropertyInfo WHERE PropertyID=#0";
var qPropertyinfo = db.QuerySingle(Propertyinfo, rPropertyId);
if(IsPost){
var sql = "INSERT INTO PropertyInfo (FePool, FeJac, FeGames) VALUES (#0, #1, #2) WHERE PropertyID=#3";
db.Execute(sql, Request["check1"], Request["check2"], Request["check3"], rPropertyId);
}
}
<form method="post">
<div>
<input type="checkbox" name="check1" value="true" />
Value 1
<br/>
<input type="checkbox" name="check2" value="check2" />
Value 2
<br/>
<input type="checkbox" name="check3" value="check3" />
Value 3
<br/>
<div>
<input type="submit" name="buttonSubmit" value="Submit" />
</div>
</form>
What I need to be able to do is check 3 columns in my database, and see if they are set to true (the columns are set as "bit"). If they are, then I want the checkbox to be shown as checked. I also want to be able to toggle these checkboxes and post "true" or "false" using a form, to post into the database.
You have a WHERE clause in your INSERT statement which makes no sense. If you are inserting, you create a new row. I suspect you intend to UPDATE an existing row in which case your SQL should be:
"UPDATE PropertyInfo SET FePool = #0, FeJac= #1, FeGames = #2 WHERE PropertyID=#3"
If a checkbox is not checked, nothing will be included for that checkbox in the Request.Form collection. If it is checked, the value passed is "on" by default, or whatever you have specified in the "value" attribute. For check1, that will be "true". For check2, that will be "check2". You need to establish whether the checkbox was actually included in the Request.Form collection and then set the values you want to commit to the database accordingly. If you want to pass true or false depending on whether the checkbox was checked, you can do this:
var c1 = !Request["check1"].IsEmpty();
var c2 = !Request["check2"].IsEmpty();
var c3 = !Request["check3"].IsEmpty();
var sql = "UPDATE PropertyInfo SET FePool = #0, FeJac= #1, FeGames = #2 WHERE PropertyID=#3";
db.Execute(sql, c1,c2,c3,rPropertyInfo);
Now that you have a series of booleans, you can use those to determine whether the checkbox is checked or not by using Conditional Attributes:
<input type="checkbox" name="check1" checked="#c1" /> Value 1<br/>
<input type="checkbox" name="check2" checked="#c2" /> Value 2<br/>
<input type="checkbox" name="check3" checked="#c3" /> Value 3<br/>
If you want to preset the values of the checkboxes from a query, you do that prior to the IsPost block:
var rPropertyId = Request.QueryString["PropertyID"];
var Propertyinfo = "SELECT * FROM PropertyInfo WHERE PropertyID=#0";
var qPropertyinfo = db.QuerySingle(Propertyinfo, rPropertyId);
bool c1 = qPropertyinfo.FePool;
bool c2 = qPropertyinfo.FeJac;
bool c3 = qPropertyinfo.FeGames;
Obviously you don't need var in front of the c1 - c3 variables in the IsPost block now.