Aspx, Entity, on my gridView I made a footer for a new button. It shows when there are items, but not when data is empty. gridView's ShowFooter = True. Not sure why it won't show when empty, is there another property I maybe missing? I know a workaround could be place a dummy row in the database, but think there should be a better way to start off at 0. If you have any more questions, please ask.
<asp:TemplateField HeaderText="New" >
<FooterTemplate >
<asp:Button ID="btnNew" CssClass="DDButton" runat="server" Text="New" CommandName="New" OnClick="new_item" />
</FooterTemplate>
</asp:TemplateField>
The footer-template is not shown when no data is present, only the EmptyDataTemplate.
<EmptyDataTemplate>
<asp:Button ID="btnNew" runat="server"
Text="New" CommandName="New"
CssClass="DDButton"
OnClick="new_item" />
</EmptyDataTemplate>
.Net 4.0 added the ShowHeaderWhenEmpty property on the GridView but unfortunately no ShowFooterWhenEmpty. However there is still the EmptyDataTemplate:
<asp:GridView runat="server" ID="myGridView">
<EmptyDataTemplate>
<asp:Button ID="btnNew" CssClass="DDButton" runat="server" Text="New" CommandName="New" OnClick="new_item" />
</EmptyDataTemplate>
</asp:GridView>
As this will not be in a GridViewRow I don't think your RowCommand event will fire but you seem to be handling the click of the button in a separate method anyway.
Reference for GridView.EmptyDataTemplate: http://msdn.microsoft.com/en-gb/library/system.web.ui.webcontrols.gridview.emptydatatemplate.aspx
Related
I have the following button on GridView and I want to display a message box to the user for confirming whether he is sure or not for buying the item.(I'm familiar with OnClientClick= return confirm('xxxxx'); ) but on Grid View it is different I can't use this method though.
<asp:ButtonField CommandName="buynow" ImageUrl="~/images/buy.png" HeaderText="BUY" ButtonType="Image"/>
Use itemtemplate field in column node in gridview markup
eg.
<asp:TemplateField HeaderText="Save">
<ItemTemplate>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="return confirm('Do you want to save?')" />
</ItemTemplate>
</asp:TemplateField>
I am working on a page that is using a gridview to display data. I have some dynamically created textboxes inside an ItemTemplate which contains several textboxes per row. Now I also have an update panel that is using ajax and should only render once my link button is clicked. The datalist is bound in my code behind after the I would like this to occur without causing a full postback. However, right now when I click the link button it causes a full post-back which eliminates my dynamically created controls.
I feel I am very close to a solution. I need one of these to happen (option 1 seems more useful):
Do not cause a postback when the linkbutton is clicked, but still render my full datalist in the update panel
or
my dynamically created controls are not removed during post back.
Here is my code:
<ItemTemplate>
[ <asp:LinkButton ID="SelectCommand" CommandName="Select" runat="server" Text="+" CssClass="sunocoBold"/> ]
<%-- start sub panel--%>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Vertical"
OnItemCommand="DataList_OnItemCommand">
<ItemTemplate>
<asp:LinkButton ID="Select" CommandName="SelectCommand" CommandArgument='<%#Eval("ship_to_num")%>' runat="server" Text='<%#Eval("ship_to_num")%>' />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
<%-- end sub panel--%>
</ItemTemplate>
<asp:TemplateField HeaderText="Site Owner" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Panel ID="pnlNames" runat="server">
</asp:Panel>
<%-- <asp:Literal ID="NameList" runat="server" /> --%>
</ItemTemplate>
</asp:TemplateField>
UpdatePanel.Triggers is made for this!
Take a look at it here: Understanding UpdatePanel.Triggers
I have a page which consists of a form on top to add new records into table1 and below that a GridView which shows records in table1 with the ability to edit.
Now the form above is simply one text box which allows you to enter names into table1, this textbox has a required field validator. The validator causes issues however when the gridview is in edit mode as when the user presses 'update' nothing is saved because the validator is triggers (as there is nothing in the form above)
How can I fix this?
You have to put CausesValidation="False" in GridView
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" CausesValidation="False"/>
You can set the RequiredFieldValidator Control and the Add button have the same ValidationGroup name. Something like this:
<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" ValidationGroup="addValidation" />
<asp:RequiredFieldValidator ID="nameRequired" ControlToValidate="txtName" runat="server" ValidationGroup="addValidation"></asp:RequiredFieldValidator>
...
<asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" />
So that, the Update button won't be impacted.
Use cause validation to false in the gridview button.
<asp:Button ID="Button2" runat="server"
CausesValidation="False"
Text="Cancel - Will Not Validate!" />
Here is an example:
http://www.java2s.com/Code/ASP/Asp-Control/CausesValidationFalse.htm
I have a gridview that is databound to a XmlDataSource. I also want to add a <columns> section with a buttonfield at the end of the gridview. When I add a columns section it prepends it (before xml columns). How could I order
<asp:XmlDataSource ID="xmlDataSource1" runat="server"
datafile="some.xml" TransformFile="some.xslt" />
<asp:GridView ID="linksGrid" runat="server"
DataSourceID="xmlDataSource1"
CssClass="adminGrid"
AllowPaging="True"
AlternatingRowStyle-BackColor="WhiteSmoke">
<Columns>
<asp:ButtonField runat="server" ButtonType="Button" Text="details" />
</Columns>
</asp:GridView>
this produces a table like this:
I want the order to be reversed: Title, Url, Button column
bones question, how could I space the columns so the modify button has no weight (fits to column) and the remaining cells to get even space?
The code below will surely help you.
<asp:GridView ID="MyGridView" runat="server" ShowFooter="True">
<Columns>
<asp:TemplateField >
<FooterTemplate >
<asp:Button ID="MyButton" runat="server" Text="Click Me"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The trick was
<asp:GridView AutoGenerateColumns="false .. />
I could simply use a asp:BoundField in my < columns > section to specify the order.
I will leave this open a bit if someone can provide an answer on how to CSS format individual columns.
I have a gridview in which when I click edit, update, and cancel button comes. I have a variable named status. If status=false then update should change to insert and if status=true then update should be update itself. What code do I have to write in rowcammand for this?
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit" Text="Edit">
</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update" Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" CommandName="Cancel" Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
You could check for the id in the RowUpdating event and take it from there. You can also offload the decision to a stored proc in the database.
GridView is not designed for insert operations. You should use FormView or DetailView for the insert purpose.
Thought you can check if the record exists in GridView_RowCommand event, you need to filter the command of your interest using condiotnal match and write the code there.
for doing inserts with GridView this might help.
Link