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>
Related
This is my aspx code:
<asp:TemplateField HeaderText="Enter_Quantity" >
<ItemTemplate>
<asp:TextBox ID ="TextBox1" runat="server" DataField="Total_Quantity" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Please add a quantity"> </asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID ="Button7" runat="server" OnClick="Button7_Click" CommandArgument="Button7" CommandName="Select" Text="Add To Cart" CausesValidation ="true" />
</ItemTemplate>
</asp:TemplateField>
Kindly note that the Button is in every Gridview Row and also the textbox column is in every Gridview row.
The problem I'm facing is that when I keep the textbox empty and then click on the button. It is showing the error message "Please add a quantity". But it is showing it in every Gridview row. I want to show this error message for that specific GridView row.
How do I solve this ?
Can someone correct my aspx code ?
Set CauseValidation = "false".
It allows you to remove validation from specific control. Suppose you're using two buttons in your page but you want only one button to validate. But as per ASP rules all button will validate your form because of CausesValidation = true by default.
i have this imagefield in a gridview
<asp:ImageField HeaderText="Image" DataImageUrlField="Image_Path" ControlStyle-Width="50" ControlStyle-Height="50"/>
the image_path is a column name from the database that retuns the image link
i need to make this field clickable so once i click on it i need to popup a form just like this field:
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:LinkButton ID="LinkButton3" CommandName="Select" onClick="popup_click" class="table-actions-button ic-table-edit" runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
i tried to put an image button instead of an image field but i'm always getting submit query instead of the image...
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" DataImageUrlFormatString="Image_Path" ControlStyle-Width="50" ControlStyle-Height="50"/>
</ItemTemplate>
does anyone know how can i fix this?
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
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
Below is my requirement. I will have two browse buttons on the page , and two upload buttons on the page.
My requirement is to have both the attachments uploaded by the user to be displayed in a gridview in one row.
Upload1 and Upload2 are the two attachments uploaded by the user and i need to get them as below in the gridview.
Attachment 1 Attachment 2 Delete
Upload1 Upload2 Delete
Can you please help me with an easy way to achieve this?
If I understand you correctly you should be able to do this by using a TemplateField when you define your columns:
<Columns>
<asp:TemplateField HeaderText="FirstColumn">
<ItemTemplate>
<asp:FileUpload ID="fu_FirstFile" runat="server" /><br/>
<asp:Button ID="btn_UPloadFirst" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SecondCOlumn">
<ItemTemplate>
<asp:FileUpload ID="fu_SecondFile" runat="server" /><br/>
<asp:Button ID="btn_UPloadSecond" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>