I have to add confirmation message on hyperlink like "Are you sure you what to that?" But I'm seeing asp first time in my life and spend last three hours on google but cant find good example to use. Any ideas?
This is how it looks right now:
<asp:HyperLinkField DataNavigateUrlFields="data"
DataNavigateUrlFormatString="SMSReport.aspx?data={0}&db=1"
HeaderText="Ataskaita" Text="Ataskaita" />
The easiest way is to make button, styled like link and redirect with javascript.
<asp:Button runat="server" id="btnRedirect" BorderWidth="0" BorderStyle="None" BackColor="White" Text="link" OnClientClick="return Redirect();"/>
function Redirect() {
return confirm('Are u sure?');
}
If you want to work in grid column you can do something like
<<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" id="btnRedirect" BorderWidth="0" BorderStyle="None" BackColor="White" Text="link" OnClientClick="return Redirect();" OnClick="btnRedirect_Click" CommandArgument='<%# Eval("YourUrl")%>' />
</ItemTemplate>
<ItemStyle Width="20px" HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
And Code behind "*.aspx.vb" file protected void btnRedirect_Click(object sender, EventArgs e)
{
Response.Redirect((sender as Button).CommandArgument);
}
Related
I want to pass the variable Date to my function HasBtnRights(). Any suggestions on how to do that?
<asp:TemplateField HeaderText="More info" Visible='<%#HasBtnRights(Eval("Date")) %>'>
<ItemTemplate>
<asp:Button runat="server" OnClientClick='openModalPopup(<%# Eval("Agreement")%>);' Text="Open"/>
</ItemTemplate>
</asp:TemplateField>
If you want to hide / show the button based on certain criteria, you can set the Visible property of the Button itself.
<asp:TemplateField HeaderText="More info" >
<ItemTemplate>
<asp:Button runat="server" Visible='<%#HasBtnRights(Eval("Date")) %>' OnClientClick='openModalPopup(<%# Eval("Agreement")%>);' Text="Open" />
</ItemTemplate>
</asp:TemplateField>
An then, in your code behind:
public bool HasBtnRights(DateTime myDate) {
// your date logic here
return true; // or return false;
}
I am trying to add a DropDownList into the DataGrid so the location column can be easily changed. I am getting an error with TemplateField, itemtemplate, label and DropDownList. I get the build error:
is not allowed within a
'System.Web.UI.WebControls.DataGridColumnCollection'.
<asp:DataGrid runat="server" CssClass="tblResults" OnItemDataBound="dgList_ItemCreated" AllowSorting="true" OnSortCommand="dgTrailer_Sort" ID="dgTrailers" DataKeyField="ID" AutoGenerateColumns="false">
<Columns>
<asp:BoundColumn DataField="TrailerOwner" HeaderText="Owner" SortExpression="TrailerOwner"></asp:BoundColumn>
<asp:BoundColumn DataField="TrailerMake" HeaderText="Trailer Make" SortExpression="TrailerMake"></asp:BoundColumn>
<asp:TemplateField HeaderText="Trailer Location">
<itemtemplate>
<asp:Label ID="lblLocation" runat="server" Text='<%# Eval("Location") %>' Visible = "false" />
<asp:DropDownList ID="ddlLocation" runat="server">
</asp:DropDownList>
</itemtemplate>
</asp:TemplateField>
<asp:BoundColumn DataField="Year" HeaderText="Year" SortExpression="Year"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
TemplateField, itemtemplate, label and DropDownList all have green lines under them and which means its not a known element.
You should use TemplateColumn, when it comes to DataGrid as it is inherited from System.Web.UI.WebControls.DataGridColumn.
TemplateField is inherited from System.Web.UI.WebControls.DataControlField, which make sense with GridView.
I have a list view to show products with prices. I put an updatePanel in ItemTemplate.
When I Click the button in contentTemplate, the Eval fields do not update, By definition the
update panel do a partial post back but it does not reflect database changes.
<ContentTemplate>
<asp:ImageButton ID="productPic" runat="server" Height="270" Width="202" ImageUrl='<%# Eval("ImageUrl") %>' />
<asp:Table ID="ColorTable" runat="server" EnableViewState="true"></asp:Table>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Literal ID="LitProductId" runat="server" Text='<%# Eval("ProductId") %>' EnableViewState="true"></asp:Literal>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>' Font-Size="8"
Font-Bold="False" Font-Names="tahoma" />
<br />
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Price","{0:0,0}") %>' Font-Size="8" Font-Bold="False" Font-Names="tahoma"
Font-Strikeout='<%# Eval("DiscountedPrice")!=DBNull.Value %>' />
<br />
<asp:Label ID="Label4" runat="server" Text='<%# Eval("DiscountedPrice","{0:0,0}") %>' Font-Size="10" Font-Bold="True" Font-Names="tahoma" ForeColor="Red"
Visible='<%# Eval("DiscountedPrice")!=DBNull.Value %>' />
<br />
</ContentTemplate>
</asp:UpdatePanel>
<br />
</td>
I appreciate any help.
It's because you are dynamically adding them in. When you post back, it loses that state and if you aren't adding them back in at that point (i.e. saving them to viewstate and adding them back in on load), it no longer knows they exist.
I found the solution.
If you want to use update panel inside a listview, you should bind the data source in code - page load.
ListView1.DataSource = new ProductFacade().GetCat3ProductListSpec(cat3Id);
ListView1.DataBind();
When you use sqlDataSource attribute, the update panel does not function as you expect.
i want to remove this column from gridview i try to add values in dropdownlist in grdiview but when i add it works fine but this column in black color appears...
how i remove it..
grdiview html
<asp:BoundField DataField="DocType" HeaderText="Document" />
<asp:BoundField DataField="DepType" HeaderText="Department" />
<asp:BoundField HeaderText="ApproveID" DataField="ApproveID"
></asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblCountry" runat="server" Text='<%#
Eval("ApproveID") %>' Visible = "false" />
<asp:DropDownList ID="DropDownList4" runat="server"
class="vpb_dropdown">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
First make sure AutoGenerateColumns="false" is set on your GridView, and then delete the lines
<asp:BoundField HeaderText="ApproveID" DataField="ApproveID"></asp:BoundField>
from your HTML. When you turn off AutoGenerateColumns, you will need to add each column manually.
I have the following Gridview which I am trying to pass a search parameter, to update the results based on that search -
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" />
<asp:Label ID="Label1" runat="server" Text="Grid not refreshed yet."></asp:Label><br />
<asp:Label ID="Label4" runat="server" Text="(Grid Will Referesh after Every Second)"Font-Bold="true"></asp:Label>
<br /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyDbConn %>"
SelectCommand="SELECT * FROM [table] WHERE BODYTEXT LIKE='"+TextBox1.text+"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
BackColor="Black" DataSourceID="SqlDataSource1" Font-Names="Arial Black"
Font-Size="Small" ForeColor="White" Height="650px" Width="930px">
</asp:GridView>
</ContentTemplate>
However I cant seem to get the SQL statement to accept the TextBox1 text that the user is entering, how can I resolve this?
You must do this in code behind.
SqlDataSource1.SelectCommand = "SELECT * FROM [table] WHERE BODYTEXT LIKE='"+TextBox1.Text;
You can do this when clicking on the search button.