I have a gridview and I need to capture the value of my label, but have it not be displayed. ANytime I set it to hidden I am no longer able to capture the value. What should I alter so the label is hidden, but I still am able to capture the value? eghead is what I am wanting to hide but still capture the value of
<td valign="top" style="text-align: left; width: 200px;">
<asp:GridView runat="server" ID="gridview1" AutoGenerateColumns="false" GridLines="Both" ShowFooter="true" >
<Columns>
<asp:BoundField DataField="rdf" HeaderText="redfern" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("egh") %>' ID="eghead" ></asp:Label>
<asp:CheckBox ID="Sans" runat="server" AutoPostBack="false" Checked='<%# Convert.ToBoolean(Eval("Remember")) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
use the
style="display:none"
in the control. This way it will not be displayed in the UI but it will be available in the client side for manipulation.
Another alternative is to set a property of your checkbox and then use it using jquery or using javascript method. The asp.net renders the custom property as it is on client side.
Related
I've a textbox that is present inside a GridView that itself is a part of user control and I'm dynamically loading this user control on page_Init.
The controls in my user control are a DropDown, a TextBox and a GridView.
Now DropDown and TextBox are able to retain values across postback but textboxes inside the GridView are not retaining the values.
Adding User Control on page init:
if (postBackCntrl.Contains("AddUserControlButton"))
{
UserControl newGrid = (UserControl)LoadControl("~/UserControl.ascx");
newGrid.ID = "test" + gridList.Count;
gridList.Add(newGrid);
}
GridView Code: TextBoxes inside GridView ItemTemplate not able to retain values across postback:
<asp:GridView runat="server" ID="grdUser" CssClass="GridTable" Width="90%" AutoGenerateColumns="false"
ShowFooter="true" OnDataBound="MergeGridViewFooter">
<Columns>
<asp:TemplateField HeaderText="ContactUs">
<ItemTemplate>
<asp:TextBox ID="txtContactUs" runat="server" CssClass="textbox" Height="60px" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnaddrow" runat="server" Text="Add Row" CssClass="ui-button jquery-ui" Style="font-size: 12px" OnClick="btnaddrow_Click" />
<asp:Button ID="btnDelRowAddress" runat="server" Text="Delete Row" CssClass="ui-button jquery-ui" Style="font-size: 12px" OnClick="btnDelRowAddress_Click" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Definition">
<ItemTemplate>
<asp:TextBox ID="txtDefinition" runat="server" TextMode="MultiLine" Height="60px" CssClass="textbox"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" Height="60px" CssClass="textbox"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I have a GridView in an asp .net application, where the Header Text of a template field is set in the Header Template of the field, as a label (where it will come from the resource file). Below is the code
<asp:GridView ID="gridView" ClientIDMode="Static" runat="server" AutoGenerateColumns="False" meta:resourcekey="grdViewResource">
<Columns>
<asp:TemplateField meta:resourcekey="TemplateFieldResource1">
<HeaderTemplate>
<asp:Label ID="lblNameHeader" Text="Name" runat="server" meta:resourcekey="lblNameHeaderResource1"/>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblNameValue" Text='<%# Eval("Name") %>'/>
</ItemTemplate>
</Columns>
</asp:GridView>
In code behind I am trying to access the HeaderText set on the column like this
var headerText = gridView.Columns[0].HeaderText;
But the value is coming Empty and I am not able to retrieve it from the gridView.Columns' HeaderTemplate property as well.
Please help me.
You have several problems with your code.
You are missing a closing </asp:TemplateField>. Your asp:Label is missing a runat="server" attribute.
If you want to use the .HeaderText property, this should be your markup:
<asp:GridView ID="gridView" ClientIDMode="Static" runat="server" AutoGenerateColumns="False" meta:resourcekey="grdViewResource">
<Columns>
<asp:TemplateField meta:resourcekey="TemplateFieldResource1" HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblNameValue" Text='<%# Eval("Name") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
If you want to use a HeaderTemplate with custom markup in it, then you need to cast the column to a TemplateField, then access the controls within it.
I have a Gridview with the following markup:
<asp:GridView ID="gdvResxKeyValue" runat="server" Width="100%" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="imgEditResxValue" CssClass="sfEdit" runat="server" ImageUrl="~/Administrator/Templates/Default/images/imgedit.png" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I need to have a handler for the Image click event. Is there any easier way to do so?
You can use an Image Button instead of Image. Try this code.
<asp:GridView ID="gdvResxKeyValue" runat="server" Width="100%" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgEditResxValue" CssClass="sfEdit" runat="server" ImageUrl="~/Administrator/Templates/Default/images/imgedit.png" OnClick="YourEventName" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You just need to specify your server side event name here.
Use an asp button and set its style to be display:none
<asp:Image ID="imgEditResxValue" CssClass="sfEdit" runat="server" ImageUrl="~/Administrator/Templates/Default/images/imgedit.png" onclick="ClickImage(this)" />
.......
<asp:Button ID="hiddenButton" runat="server" OnClick="hiddenButton_Click" style="display:none"></asp:Button>
<script type="text/javascript">
function ClickImage(imageControl)
{
document.getElementById('<%=hiddenButton.ClientID%>').click();
}
</script>
This will raise the server side event of the button and you can do your work there.
Try this:
jquery Solution
<asp:Image ID="imgEditResxValue" CssClass="sfEdit" runat="server" ImageUrl="~/Administrator/Templates/Default/images/imgedit.png" onclick="this.next().click()"/>
<asp:LinkButton Text="text" runat="server" OnClick="call_method"/>
Let me start off by saying I know how to use CausesValidation and ValidationGroup. I have bizarre situation where I have an Ajax Tab container. Each tab has a gridview and the rows that generate in the gridviews all have a TemplateField containing an 'Add' button. The buttons in the gridview and tab containers all use ValidationGroup to prevent any cross contamination and all the 'Add' buttons are set to CausesValidation = "false"
I just added the last gridview and the 'Add' button triggers all validators on the page. Once more the 'Add' button is set as CausesValidation = "false" so there is NO reason for it to behave in this fashion. I even set this value on the front end AND in the code behind.
For attempts I have tried the suggestions in these links: "Solution 1" and "Solution 2"
Has anyone else come across this and found a solution?
Edit Request for code:
I will post only the Tab Panel in question as the whole container is almost 500 lines
<asp:TabPanel ID="tab_Browse" runat="server" HeaderText="Browse">
<ContentTemplate>
<table id="browseTable">
<tr>
<td>Category</td>
<td>
<asp:DropDownList ID="browseDDL" runat="server" AppendDataBoundItems="True">
<asp:ListItem Text="All categories" Value="999"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:Button ID="btnBrowse" runat="server" Text="Browse" ValidationGroup="vgBrowse" OnClick="btnBrowse_Click" />
</td>
</tr>
</table>
<asp:GridView ID="gvBrowse" runat="server" AutoGenerateColumns="false" AllowPaging="true" PageSize="8"
OnPageIndexChanging="gvBrowse_PageIndexChanging" DataKeyNames="foodId"
OnRowDataBound="gvBrowse_RowDataBound" Width="790px">
<Columns>
<asp:TemplateField HeaderText="Food ID" Visible="false">
<ItemTemplate>
<%# Eval("foodId") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<%# Eval("Shrt_Desc") %> (100g)
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Calories" ItemStyle-Width="50px">
<ItemTemplate>
<%# Eval("cals") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fat Grams" ItemStyle-Width="75px">
<ItemTemplate>
<%# Eval("fat") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Carbs" ItemStyle-Width="50px">
<ItemTemplate>
<%# Eval("carbs") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="110px">
<ItemTemplate>
<asp:Button ID="browseAdd" runat="server" CausesValidation="false" Text="Add to meal" CommandArgument="Standard" OnClick="showingEntry" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="gvRowStyle" />
<HeaderStyle CssClass="gvHeader" />
<AlternatingRowStyle CssClass="altRow" />
</asp:GridView>
</ContentTemplate>
</asp:TabPanel>
Edit 2 Another interesting tidbit. If I put OnClientClick="alert(Page_IsValid)" on my add button it returns true even though the validators in the others tabs are triggered. if i click the button a second time it returns false and my codebehind fails as if the page posted back but skipped the OnDataBound method
I ended up resolving this problem by preloading the gridview with an empty row. Makes no sense as to why this resolved the problem, but it does.
I currently have a GridView in a pop-up control. The GridView is embedded in an UpdatePanel and I have the window pop-up showing nothing on it. However, when I debug through it I see that the GridView has data in it and it is bound, but I am not noticing any changes. I even tried to call the Update method on the UpdatePanel, but received no changes in that either.
Basically what I wish to do is show a blank page up until my data has been loaded in. After the GridView has the data bound to it I would like it to be visible. Please find the below code snippet of the current process.
ASPX source:
<dx:ASPxPopupControl ID="ASPxPopupItem" runat="server" ClientIDMode="AutoID" LoadingPanelImagePosition="Bottom"
Modal="True" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
EnableAnimation="False" HeaderText="Item Checker"
Width="614px">
<ContentCollection>
<dx:PopupControlContentControl ID="PopupCoverageItem" runat="server" SupportsDisabledAttribute="True">
<table style="width: 611px" cellpadding="3" cellspacing="3">
<tr>
<td align="center">
Title
</td>
</tr>
<tr>
<td colspan="2">
<div style="height: 75px; overflow: auto; width: 595px;">
<asp:UpdatePanel runat="server" ID="udpItems" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView runat="server" ID="gvTitles" Width="575px" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="90px">
<ItemTemplate>
<center>
<asp:ImageButton OnClick="btnSelect_Click" ID="lnk_Select" runat="server" CommandArgument='<%# Eval("title") %>'
ImageUrl="~/images/save.png" ToolTip="Choose this record" />
</center>
</ItemTemplate>
<HeaderStyle Width="90px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:BoundField HeaderText="Item ID" DataField="item_id" SortExpression="item_id" />
<asp:BoundField HeaderText="Title" DataField="title" SortExpression="title" />
<asp:BoundField HeaderText="Date" DataField="date" SortExpression="date" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</td>
</tr>
<tr>
<td align="center">
<asp:Button runat="server" ID="btnCancelTitle" Text="Cancel" CssClass="popupButton"
OnClick="btnCancelTitle_Click" />
</td>
</tr>
</table>
</dx:PopupControlContentControl>
</ContentCollection>
</dx:ASPxPopupControl>
C# back end:
// Bind the data from the returning SQL query and update
gv.DataSource = npgDat;
gv.DataBind();
udpItems.Update();
Unfortunately there isn't much more of the C# back-end that I can show since we're using a company specific Query tool that works well in other situations.
Thanks
Are you sure an ASPxPopupControl supports having an UpdatePanel as content? I'd try getting rid of the UpdatePanel and see if the GridView works as expected then, or try moving the UpdatePanel (with the GridView still inside it) outside of the ASPxPopupControl and see if that works. If the problem is having the UpdatePanel inside the ASPxPopupControl, then you'll probably have to contact DevExpress for more help, as that would lead me to believe it's a problem with their control.
Update
Based on your comment below, you may want to look into Example: How to show the ASPxLoadingPanel while the content is loading inside the ASPxPopupControl over on the DevExpress support forum.