I have a problem in updating date using gridview. I want to add ajax control toolkit calendar control inside the gridview boundfield.
My sample gridview will look like this. these gridview details are from table.so, my Date column in BOUNDFIELD
when I update date, I need ajax calendar control should pop up to select date.
how to achieve this?
You need to use Item Templates......
Example :
<asp:TemplateField HeaderText="Is Active">
<ItemTemplate>
<asp:Label ID="lblIsActive" runat="server" Text='<%# Eval("YourValue").ToString() %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
// Add your item here (Like Textbox With Caleder control)
</EditItemTemplate>
</asp:TemplateField>
Related
I am new to asp.net, forgive my newbie question.
I have a listview which displays all item info (ItemID,Item name).
I bound the item name to a hyperlink control. now what i want to do is that when i click the hyperlink i want to get the ID and navigate the item detail page. i tried using selected index but it still returns null. here's my code.
On the listview itemTemplate code
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="ItemDetails.aspx"> <%# Eval("[ItemName]") %>
</asp:HyperLink>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("[ItemID]") %>'/>
Please help.thanks in advance
Instead of Hyperlink, I used LinkButton in ItemTemplate If u want to pass the selectedId to the next page u can pass using Query String
<asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="120px">
<ItemTemplate>
<asp:LinkButton ID="lnk_ViewDetails" runat="server" Text='View Details' PostBackUrl='<%#"~/ViewDetailss.aspx?Id="+Eval("ID")%>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
If u want to encrypt querystring Please refer This Link
I have a gridview with a dropdownlist for the products description in the footer template.
There is no way to create a SelectedIndexChanged in the IDE and writing it out manually produces an error? How to create code to handle the Selection change? I need to populate the product ids when the product description is selected.
"EDITED"
I tried using the gridview rowediting event assuming that if a row item was changed (ie, a new selection in the dropdown, it would fire, but it doesn't) It appears a gridview event has to be fired when that dropdown list changes, that's where i need the code to go. Any ides on what event?
Here is what the template field markup is:
<asp:TemplateField HeaderText="description" SortExpression="description">
<FooterTemplate>
<asp:DropDownList ID="ddlProductDesc" runat="server" DataSourceID="edsProductDesc" DataTextField="description"
OnSelectedIndexChanged="ddlProductDesc_SelectedIndexChanged">
</asp:DropDownList>
<%--<asp:TextBox ID="tbInsertdescriptiton" Width="350" runat="server"></asp:TextBox>--%>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblProdDesc" runat="server" Text='<%# Bind("description")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Take a look at this:
http://www.c-sharpcorner.com/blogs/7228/asp-net-gridview-dropdown-with-related-records-in-textbox.aspx
I am using a multi page gridview to display bunch of data. Here is the code of the gridview.
<asp:GridView ID="unverifiedlist" runat="server" AutoGenerateColumns="false" AllowSorting="true" AllowPaging="true" OnRowDataBound="unverifiedlist_RowDataBound" style="font-size:12px" >
<Columns><asp:BoundField HeaderText="Surname" DataField="Surname" ReadOnly="true"/></Columns>
<Columns><asp:BoundField HeaderText="Firstname" DataField="Givenname" ReadOnly="true"/></Columns>
......
<Columns><asp:TemplateField HeaderText="Options" >
<ItemTemplate>
<asp:DropDownList ID="options" runat="server" AutoPostBack="true" OnSelectedIndexChanged="options_SelectedIndexChanged">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="1">Verified</asp:ListItem>
<asp:ListItem Value="2">Rejected</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Reason">
<ItemTemplate>
<asp:TextBox ID="reason" runat="server" OnTextChanged ="reason_TextChanged"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings Visible="false"/>
</asp:GridView>
<asp:DropDownList ID="PageSelect" AutoPostBack="true" runat="server" OnSelectedIndexChanged="PageSelect_SelectedIndexChanged"></asp:DropDownList>
there is a column called "option" which contains a dropdownlist, and it will postback everytime when the selected index was changed to save the edited row. I am trying to avoid this frequent postback. So i think if I can save the whole page before user turn to the next page.
The problem is the "PageSelect" dropdownlist's postback will trigger the page reload first, then onselectedindexchanged event, at this point, the gridview already turned to the next page. So can anyone give me some advice?
You can set EnableSortingAndPagingCallBacks property of the grid view to true , but that wont work if you are using template fields in your gridview, for maintaining the state of the page, you will have to keep the value of current page in session and on page load you can check the session..
I used the gridview itself's paging navigation control instead of my dropdownlist at last. Then I am able to use the pageindexchanging event to save the current page into a session before it goes to the next page
I have a DetailsView control with a template field as follows:
<asp:TemplateField SortExpression="Title">
<ItemTemplate>
<asp:TextBox ID="txtMessageTitle" Text='<%# Bind("Title") %>' runat="server">
</asp:TextBox>
<asp:Button ID="btnUpdateTitle" runat="server" Text="Update"
CommandName="UpdateTitle" CommandArgument='<%# Bind("MessageID") %>' oncommand="btnUpdateCommand"/>
</ItemTemplate>
</asp:TemplateField>
The Details View is wrapped inside an UpdatePanel.
When the user clicks on btnUpdateButton I'd like to be able to retrieve the textbox (txtMessageTitle) value in code behind and by using CommandArgument of the button, update the appropriate MessageTitle in database. How can I retrieve the textbox value inside the DetailsView control from the Command event of my button?
Thanks.
use the following:
TextBox txtMessageTitle = detailsViewName.FindControl("txtMessageTitle") as TextBox;
string text = txtMessageTitle.Text;
I have an LinkButton column in my GridView:
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
let's assume that I need to bound to that GridView a list of some items, where some of them shoud have visible that LinkButton, some not. So that is the question: how - while bounding/after bound - can I realize that scenario, I mean show LinkButtons (with different CommandArgument) where there are needed ?
You have 3 options:
Handle the RowDataBound event: find the button in the row and set the visible property
Bind a property/column in the datasource: <asp:LinkButton Visible='<%# Bind("Editable") %>'
create a method returning a boolean in the page and use it: <asp:LinkButton Visible='<%# IsButtonVisible(DataBinder.Eval(Container.DataItem, "ID")) %>'