I have a text box and button inside of my ASPXGridview, DetailRow view. So when it's expanded I need to type text and click button and on server side to get value from the textbox.
Here is my code. The problem is somewhere on postback I'm loosing text value. So text box is empty
protected void Button1_Click(object sender, EventArgs e)
{
ASPxGridView grid = EmailGridView;
for (int i = 0; i < grid.VisibleRowCount; i++)
{
var txtDescription = (ASPxMemo)grid.FindDetailRowTemplateControl(i, "txtDescription");
if(txtDescription != null)
{
var text = txtDescription.Text;
}
}
}
<dxwgv:ASPxGridView ID="EmailGridView" KeyFieldName="ThreadId" runat="server" AutoGenerateColumns="False"
OnHtmlRowCreated="EmailGridView_HtmlRowCreated" SettingsDetail-AllowOnlyOneMasterRowExpanded="true"
SettingsBehavior-ConfirmDelete="true" OnHtmlRowPrepared="EmailGridView_HtmlRowPrepared"
OnRowDeleted="EmailGridView_RowDeleted">
<SettingsBehavior ConfirmDelete="True" />
<Columns>
<dxwgv:GridViewDataTextColumn Caption="ID" FieldName="Id" VisibleIndex="0">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewCommandColumn VisibleIndex="5" Caption=" ">
<DeleteButton Visible="True">
</DeleteButton>
</dxwgv:GridViewCommandColumn>
</Columns>
<SettingsDetail ShowDetailRow="true" />
<SettingsBehavior ConfirmDelete="True" />
<SettingsDetail AllowOnlyOneMasterRowExpanded="True" ShowDetailRow="True" />
<Templates>
<DetailRow>
<dxwgv:ASPxGridView ID="EmailSubGridView" Width="750px" OnBeforePerformDataSelect="EmailSubGridView_BeforePerformDataSelect"
runat="server" AutoGenerateColumns="False"
onhtmlrowcreated="EmailSubGridView_HtmlRowCreated">
<Columns>
<dxwgv:GridViewDataTextColumn Caption="MessFrom" FieldName="MessFrom">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn Caption="Message" FieldName="Message">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn Caption="SendDtm" FieldName="SendDtm">
</dxwgv:GridViewDataTextColumn>
</Columns>
<StylesEditors>
<ProgressBar Height="25px">
</ProgressBar>
</StylesEditors>
</dxwgv:ASPxGridView>
<dx:ASPxMemo ID="txtDescription" runat="server" Width="170px" Height="71px"></dx:ASPxMemo>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Reply" />
</DetailRow>
</Templates>
Conny,
The ASPxGridView has callbacks built into it so I recommend using that approach as it's easier and it gives you a better user experience. The find method you're using requires the visiblerowindex.
Take a look a this code central example to see how to get data from the server:
How to bind the detail GridView to data based on the end-user input
If you want these process when you are expanding your ASPxGridview, you should use DetailRowExpandedChanged event.
This event works when you expand or collapse your ASPxGridview.
Mehul's example is very good actually for this situation. After that, if you still have a problem, you can ask your question in Devexpress Support. They are really helpful and quick.
Related
<telerik:RadGrid runat="server" ID="rdReport" AutoGenerateColumns="false" AllowPaging="true" Skin="Metro" OnItemCommand="ItemCommand" OnItemDataBound="rdReport_ItemDataBound" OnPreRender="rdReport_PreRender" DataSourceID="FountainSource" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
<MasterTableView DataKeyNames="ID" CommandItemDisplay="None">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" />
<telerik:GridBoundColumn DataField="LocName" HeaderText="Location" ReadOnly="true" />
<
<telerik:GridBoundColumn DataField="Field1Value" HeaderText="Custom Field1" />
<telerik:GridBoundColumn DataField="Field2Value" HeaderText="Custom Field2" />
<telerik:GridBoundColumn DataField="Field3Value" HeaderText="Custom Field3" />
<telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
On Edit, I like to make a field invisible.
I am using the following code which works but want to check to see if it is best practice:
protected void rdReport_ItemDataBound(object sender, GridItemEventArgs e)
{
// Edit Mode
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
{
GridEditFormItem fndColumn = (GridEditFormItem)e.Item;
fnColumn["Field1Value"].Parent.Visible = false;
}
}
The solution which was provided by you is perfect but it would be nice if you will also add UniqueName property in each column. If we will not assign the UniqueName than it is consider DataField value as UniqueName.
ASPX
<telerik:GridButtonColumn DataField="Field1Value" HeaderText="Custom Field1" UniqueName="Field1Value" />
ASPX.CS
protected void rdReport_ItemDataBound(object sender, GridItemEventArgs e)
{
// Edit Mode
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
{
GridEditFormItem fndColumn = (GridEditFormItem)e.Item;
fnColumn["Field1Value"].Parent.Visible = false; // "Field1Value" is column uniquename
}
}
Let me know if you required more information.
This is just a suggested alternative. I've worked with telerik a few times, and it is a pain to say the least. What you could do is also add a tertiary condition to the parent container. If in edit mode, then show a class, such as 'edit', or 'current'. If not in edit mode, don't show the class. Then, in your CSS you can select for whatever element you want to hide.
<div>
<input type="text" id="whateverisgenerated" class="uniqueclass" />
</div>
Then, when in edit mode, you will have
<div class="edit">
<input type="text" id="whateverisgenerated" class="uniqueclass" />
</div>
With your CSS:
div.edit input.uniqueclass { display: none; }
As for your telerik control (I just grabbed something from your code), you can do the following to add your class:
<telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" CssClass="uniqueclass" />
I added CssClass="uniqueclass" in the control above.
What I provided is just an example. I hope you find a use for it. Thanks
ASP newbie here, in my website I need to set a session variable when I click the menu item( not on page load or pre init or init).
How can I achieve this, I have a menu control in my master page which has a sitemap file attached to it?
How to know when a particular menu item is clicked?
<asp:Menu ID="mainMenu" runat="server" DataSourceID="siteMapSource"
StaticDisplayLevels="10" Width="150px">
<StaticSelectedStyle CssClass="menuNodeSelected" />
<LevelMenuItemStyles>
<asp:MenuItemStyle Font-Bold="True" Font-Underline="False" />
</LevelMenuItemStyles>
<StaticMenuItemStyle CssClass="menuNode" />
</asp:Menu>
<asp:SiteMapDataSource ID="siteMapSource" runat="server" ShowStartingNode="False" />
Based on your code and documentation finded on msdn you should have something like this:
On Markup Code (that will result in HTML which will be sent to Client)
<asp:Menu ID="mainMenu" runat="server" DataSourceID="siteMapSource"
StaticDisplayLevels="10" Width="150px"
OnMenuItemClick="NavigationMenu_MenuItemClick">
<StaticSelectedStyle CssClass="menuNodeSelected" />
<LevelMenuItemStyles>
<asp:MenuItemStyle Font-Bold="True" Font-Underline="False" />
</LevelMenuItemStyles>
<StaticMenuItemStyle CssClass="menuNode" />
</asp:Menu>
<asp:SiteMapDataSource ID="siteMapSource" runat="server" ShowStartingNode="False" />
You should set a method to be called on server side OnMenuItemClick, this will rise the event of menu click. That event is (in our case): NavigationMenu_MenuItemClick.
On Code-Behind you can do whatever you want when an menu item is selected.
void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)
{
// Display the text of the menu item selected by the user.
Message.Text = "You selected " + e.Item.Text + ".";
Session["variable"] = e.Item.Text;
}
In e.Item.Text; you find what element has been selected.
Based on: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.menuitemclick(v=vs.110).aspx
The ASP:Menu has an Click event. You can handle this event to set the Session Variable.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.menuitemclick.aspx
Declare it:
<asp:Menu ID="mainMenu" runat="server" onmenuitemclick="NavigationMenu_MenuItemClick" ...
And handle it:
void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)
{
// Display the text of the menu item selected by the user.
Message.Text = "You selected " +
e.Item.Text + ".";
}
I am displaying my data in a devexpress gridview. One of the column is state value. When the grid is edited, I have to show the state in a combobox, so that the user could change the state by choosing a different state. Currently it is displayed in a textbox, since it is the default. Essentially when the user clicks the edit button, a combobox should be displayed as part of the edit controls, and the combobox should be populated with all possible states in the codebehind and the selected value should be the initial value on the grid. It is very easy do it in MS gridview. But I couldn't see any sample code for how to do it in the devexpress gridview.
Thanks
Use GridViewDataComboBoxColumn. Declare datasource and attach it to combo box column or populate it in code behind. This example contains both variants.
You can also take a look at DevExpress grid editing demos.
<dx:GridViewDataTextColumn FieldName="FieldName" VisibleIndex="4">
<EditItemTemplate>
<dx:ASPxComboBox ID="ASPxComboBox1" runat="server" DataSourceID="newDataSource" >
</dx:ASPxComboBox>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
You'll need to set the datasource so you'll get the list of values
If you don't have a data source and want to include the combo box items in your code, here's another way to create the column:
<dx:GridViewDataComboBoxColumn FieldName="QAAproval" VisibleIndex="11" Width="30px">
<PropertiesComboBox>`enter code here`
<Items>
<dx:ListEditItem Text="GENERIC" Value="GENERIC" />
<dx:ListEditItem Text="FAIR" Value="FAIR" />
<dx:ListEditItem Text="VSE" Value="VSE" />
<dx:ListEditItem Text="ECAV" Value="ECAV" />
<dx:ListEditItem Text="FMMDS" Value="FMMDS" />
<dx:ListEditItem Text="CLEAR" Value="CLEAR" />
</Items>
</PropertiesComboBox>
<CellStyle Font-Size="XX-Small">
</CellStyle>
</dx:GridViewDataComboBoxColumn>
Edit the GridView Template, and in the EditTemplate of the field, add the dropdownbox. It might come to look like this
<dx:GridViewDataTextColumn Caption="Field Name"
FieldName="FieldName" VisibleIndex="3">
<EditItemTemplate>
<cc1:DropDownList ID="DropDownList1" runat="server">
</cc1:DropDownList>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
So when you edit that row, it will show the DDL
I have used the following code to have combo box in the aspxgridview.
I hope this example helps :
<dx:GridViewDataComboBoxColumn FieldName="DatabaseFieldName" Settings-FilterMode="DisplayText"
Width="3%" VisibleIndex="3" Visible="True" Caption="Priority" Settings-AutoFilterCondition="Contains"
HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center" CellStyle-HorizontalAlign="Center"
CellStyle-VerticalAlign="Top">
<PropertiesComboBox ValueType="System.String" DataSourceID="objDataSourceID"
Width="200px" Height="25px" TextField="TextFieldName" ValueField="ValueFieldName"
IncrementalFilteringMode="StartsWith">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
I have the following code
Javascript
function RowDblClick(sender, eventArgs)
{
window.radopen("SourceFileAdmin.aspx?SourceSystemFileId=" + eventArgs.getDataKeyValue("SourceSystemFileId"), "UserListDialog");
}
Aspx Grid Code
<telerik:RadGrid ID="RadGrid" runat="server" AllowPaging="True" AllowSorting="True"
GridLines="None" ShowGroupPanel="True" Skin="Black" AutoGenerateColumns="False"
Width="100%" AllowAutomaticInserts="false" AllowAutomaticUpdates="false" PagerStyle-Mode="NumericPages"
OnItemInserted="GridItemInserted"
onitemdatabound="GridItemDataBound">
.............................................
........................................
..................................................
<ClientSettings>
<Selecting AllowRowSelect="true" />
<ClientEvents OnRowDblClick="RowDblClick" />
</ClientSettings>
</telerik:RadGrid>
<asp:Button ID="AddSrcButton" runat="server" Text="Add New" OnClientClick="return ShowInsertForm();" />
My actual question is to disable or enable RowDblClick property based on the user permission
This is my sample code in the aspx.cs file where i want to set the edit or view permission for radgrid
this.AddSrcButton.Enabled = this.Privilige.CanModify;//the value will be true or false
this.RadGrid.Enabled=this.Privilige.CanModify;
//the value will be true or false ,based on this value i want to enable/disable my rowdblclick,can any one help out to figure out where i am doinfg wrong
You can set the row double click on the server side programatically
if(!this.Privilige.CanModify)
RadGrid.ClientSettings.ClientEvents.OnRowDblClick = "";
Beware though to renable the page you will probably need to refresh it all to get the clientside javascript to be loaded again, unless you move that into the .cs file
I create have a TreeView bound to a SiteMap. It works great.
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:TreeView>
Now I want to change the way the selected node looks.
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
<NodeStyle ImageUrl="~/Images/Page.png" />
<SelectedNodeStyle ImageUrl="~/Images/Page_Hot.png" />
</asp:TreeView>
The thing is, the current page is not automatically selected on the tree (why MSFT, why?). This is not the end of the world. So, I created a little code behind like this:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
return;
TreeView1.TreeNodeDataBound += new TreeNodeEventHandler(TreeView1_TreeNodeDataBound);
}
void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
var _CurrentUrl = Request.Url.AbsolutePath;
e.Node.Selected = (e.Node.NavigateUrl == _CurrentUrl);
}
But still the node is not selected. My gut tells me it's the wrong event.
Any help?
Thanks // Jerry
The AbsolutePath vs the NavigateUrl might be suspect, one is a relative path (NavigateUrl) and the other, as the name implies, is an absolute path. If you run in debug mode can you see that the two values are indeed the same?
Well, this is really annoying. I suppose the "technical" answer to my question is that it worked all along. However, the real issue is that ImageUrl in the SelectedNodeStyle appears to be ignored. I am going to paste a little more of my solution so you can see what I have, but no matter what I try, ImageUrl in the SelectedNodeStyle is ignored.
(PS: .Net4)
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" ShowExpandCollapse="false">
<NodeStyle ForeColor="White" Font-Bold="true" NodeSpacing="5" HorizontalPadding="5"
ImageUrl="~/Images/Page.png" />
<SelectedNodeStyle Font-Bold="true" NodeSpacing="5" HorizontalPadding="5" Font-Underline="true"
ImageUrl="~/Images/Page_Hot.png"/>
<HoverNodeStyle ForeColor="Navy" />
</asp:TreeView>