I want to display records in Horizontal Layout. I used Data List control for the same which displays only 5 records.
I want select functionality so that when i click the items in Data List , complete details will be displayed in another page.
Thanks a lot.
<div style="margin-left: 25%; margin-top: 5%">
<asp:DataList ID="dlTop5" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" RepeatColumns="5"
ItemStyle-Width="40%" >
<ItemTemplate>
<table>
<tr>
<td rowspan="3" style="margin-left: 3%">
<asp:ImageButton ID="imgServant" runat="server" ImageUrl='<%#Eval("photo")%>' Height="150px"
Width="150px" />
</td>
<td style="width: 50%">
<asp:Label ID="lblName" runat="server" Text='<%#Eval("name")%>' Font-Bold="true"
ForeColor="BlueViolet"></asp:Label>
</td>
</tr>
<tr>
<td style="width: 50%">
<asp:Label ID="lblPhone" runat="server" Text='<%#Eval("phone")%>' ForeColor="BlueViolet"> </asp:Label>
</td>
</tr>
<tr>
<td style="width: 50%">
<asp:Label ID="lblSrno" runat="server" Text='<%#Eval("sysno")%>'> </asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnViewMore" runat="server" Text="View More" />
</FooterTemplate>
</asp:DataList>
</div>
</asp:Content>
This is what I do ...
<asp:DataList ID="DataList1" runat="server" BorderColor="Black" BorderWidth="1px"
DataSourceID="SqlDataSource2" GridLines="Both" RepeatDirection="Horizontal"
ShowFooter="False" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("RollCallPeriod") %>' OnClick="LinkButton1_Click"></asp:LinkButton><br />
</ItemTemplate>
</asp:DataList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ATCNTV1ConnectionString %>"
SelectCommand="SELECT RollCallPeriod FROM tblBoardingRollCallPeriods">
</asp:SqlDataSource>
And use the OnClick event to fire up a call into your code behind to reveal a panel for example and put all your specific code about the selection inside the panel - ie: Gridview, etc.
You don't have to use a LinkButton of course. It can be anything you want - a button, a hyperlink, etc
Labels do not have OnClick etc. Unless you "trap" them using JavaScript like mouseclick or mouseover.
Related
I am facing problems while using the ListView Control in asp.net
I used two buttons links in a ListView ItemTemplate. For both buttons, I used Command Name and Command Argument. But first one is working fine and the second one is giving errors. I.e.
System.InvalidOperationException: Insert can only be called on an insert item. Ensure only the InsertTemplate has a button with CommandName=Insert.
If I want to add the InsertTemplate, where do we have to place it?
I am copying my code. Please help me.
Design View :
<asp:ListView ID="ListView1" runat="server" GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1" GroupItemCount="2" OnPagePropertiesChanging="ListView1_PagePropertiesChanging" DataKeyNames="InventoryID" OnItemCommand="ListView1_ItemCommand">
<LayoutTemplate>
<table width="100%">
<tr style="background-color:lightblue;color:blue;text-align:center;font-size:25px;font-weight:bold">
<td colspan="2">Available Books</td>
</tr>
<asp:PlaceHolder ID="groupPlaceHolder1" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder ID="itemPlaceHolder1" runat="server"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<table cellpadding="2" cellspacing="0" border="1" style="width:100%;height:100px; border:dashed 1px #04AFEF;background-color:#B0E2F5">
<tr>
<td>
<asp:Button ID="btnReview" runat="server" Text="Review" CommandName="Select" CommandArgument='<%# Eval("InventoryID") %>'/>
</td>
<td></td>
<td>
<asp:Button ID="btnAddToCart" runat="server" Text="Add To Cart" CommandName="Insert" CommandArgument='<%# Eval("InventoryID") %>' />
</td>
</tr>
</table>
</td>
</ItemTemplate>
</asp:ListView>
Well you can insert a InsertItemTemplate like here :
<InsertItemTemplate>
<tr style="background-color:#D3D3D3">
<td valign="top">
<asp:Label runat="server" ID="FirstNameLabel"
AssociatedControlID="FirstNameTextBox" Text="First Name"/>
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%#Bind("FirstName") %>' /><br />
<asp:Label runat="server" ID="LastNameLabel"
AssociatedControlID="LastNameTextBox" Text="Last Name" />
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%#Bind("LastName") %>' /><br />
<asp:Label runat="server" ID="EmailLabel"
AssociatedControlID="EmailTextBox" Text="E-mail" />
<asp:TextBox ID="EmailTextBox" runat="server"
Text='<%#Bind("EmailAddress") %>' />
</td>
<td>
<asp:LinkButton ID="InsertButton" runat="server"
CommandName="Insert" Text="Insert" />
</td>
</tr>
</InsertItemTemplate>
Used From : https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.insertitemtemplate(v=vs.110).aspx
I'm retrieving an article from my db but it appears in a too long one line ! ,so I want to display it in a multiline way in my webpage
I'm using a datalist element to receive and show the data retrieved from db
articlesDL.DataSource = DS.select_all_articles();
articlesDL.DataBind();
and that's what my datalist appear in tags :
<asp:DataList ID="articlesDL" runat="server">
<ItemTemplate>
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:ImageButton ID="ImageButton1" runat="server" Height="50px" ImageUrl='<%# "~/images/"+Eval("imageurl")+".jpg" %>' Width="50px" />
</td>
<td class="auto-style2">
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl='<%# "~/reviewart.aspx?id="+Eval("articleid") %>' Text='<%# Eval("articlebody") %>'></asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
Try to set width to the panel where you are showing the data.
<div ID="articlesDL">
</div>
<style>
#articlesDL
{
width:100%;
}
</style>
I have this code that creates a check box an image and a label.
I want to view only three cells in each row, how can I do that??
<table class="checkbox-container" style="margin-top: 15px; width: 50%;">
<tr>
<asp:Repeater EnableViewState="true" ID="rptStart" runat="server">
<ItemTemplate>
<td style="width:25%;">
<asp:CheckBox ID="chkColor" runat="server" />
<img id="imgCompStatusStar" runat="server" enableviewstate="false" src="../images/" />
<asp:Label id="lblStarDescription" class="floating-left" runat="server" CssClass="test"/>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</table>
Change your markup to this:
<asp:Repeater EnableViewState="true" ID="rptStart" runat="server">
<HeaderTemplate>
<table>
<tr>
</HeaderTemplate>
<ItemTemplate>
<%#If((Container.ItemIndex <> 0 AndAlso Container.ItemIndex Mod 3 = 0), "</tr><tr>", String.Empty)%>
<td style="width: 25%;">
<asp:CheckBox ID="chkColor" runat="server" />
<img id="imgCompStatusStar" runat="server" enableviewstate="false" src="../images/" />
<asp:Label ID="lblStarDescription" class="floating-left" runat="server" CssClass="test" />
</td>
</ItemTemplate>
<FooterTemplate>
</tr></table>
</FooterTemplate>
Currently i'm working on my final year project.
In a webpage which loads data in gridview, each row has on button which will popup a window and ask for error to write inside **textbox** and submit that error on server.
On the serverside i require two values, first one is the primary key of that row and the error that is written inside **textbox**. It is easy to get primary key value but i'm unable to get value in side the textbox.
I'm attaching the code of .aspx file:
<asp:GridView ID="gvPODetails" runat="server" DataSourceID="Inspection_SqlDataSource"
EnableModelValidation="True" AllowSorting="True" AutoGenerateColumns="False"
BackColor="#CCCCCC" BorderColor="Black" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" ForeColor="Black" CellSpacing="2">
<Columns>
<asp:BoundField DataField="ProductCode" HeaderText="ProductCode" SortExpression="ProductCode" />
<asp:BoundField DataField="MaterialCode" HeaderText="MaterialCode" SortExpression="MaterialCode" />
<asp:TemplateField>
<ItemStyle BorderStyle="None" BorderColor="Transparent" BorderWidth="0px" />
<ItemTemplate>
<asp:LinkButton ID="lnkbtnOk" OnClick="Ok_Click" CommandArgument='<%# Eval("Identity")%>'
runat="server" Text="Ok"></asp:LinkButton>
<asp:LinkButton ID="lnkbtnReject" runat="server" Text="Reject"></asp:LinkButton>
<asp:Panel ID="popUp_Data" runat="server" CssClass="modelPopup" Style="display: none;">
<table style="padding: 10px 10px 10px 10px; width: 100%;">
<tr>
<td>
</td>
<td align="right">
<input id="close_popup" type="image" src="../Images/closebox.gif" />
</td>
</tr>
<tr valign="top">
<td align="right">
<asp:Label ID="lblError" Text="Error" runat="server" CssClass="fontStyle"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtError" runat="server" CssClass="ta"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
<asp:Button ID="btnSubmit" runat="server" CssClass="sbmt" Text="Reject Item" OnClick="Reject_Click"
CommandArgument='<%# Eval("Identity")%>' />
</td>
</tr>
</table>
</asp:Panel>
<asp:ModalPopupExtender ID="popUp_Data_ModalPopupExtender" runat="server" DynamicServicePath=""
Enabled="True" BackgroundCssClass="modelBackground" PopupControlID="popUp_Data"
TargetControlID="lnkbtnReject" CancelControlID="close_popup">
</asp:ModalPopupExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Label runat="server" ID="lblNoDataFound" Text="No Machine Found."></asp:Label>
</EmptyDataTemplate>
</asp:GridView>
What i want is the data inside textbox with id txtError.
Since it is a repeating item, you cannot access it directly using its id. You can use FindControl instead as follows:
var textBoxAux = gridView.Rows[index].FindControl("txtError") as TextBox;
You need to find the index of the row in the event you are handling.
EDIT: finding the index...
Pass the DataItemIndex in the CommandArgument ( instead of the identity ) if applicable.
CommandArgument='<%# Container.DataItemIndex %>'
Ref: ASP.NET GridView RowIndex As CommandArgument
I Have A web Page Having Two TextBox and Two Image Button on Image Button Click
open the ModalPopupExtender having Grid inside the ModelPopExtender. mean Grid Pop open on image button CLick. Problem is That when i click the button It show ModelPopExtender and Close.
auto and Page Post Back and Again Pop open. I want that pop is open stage not to post back.
aspx Code is like:
"
<asp:ImageButton ID="imgbtnExpenseGL" runat="server" ImageUrl="../../Images/icon_popup.gif" ImageAlign="Top" OnClientClick="ShowPopupExpGLSearch();" />
<AjaxToolKit:AutoCompleteExtender
ID="AutoCompleteExtender1"
runat="server"
CompletionInterval="100"
CompletionSetCount="12"
EnableCaching="false"
MinimumPrefixLength="1"
ServiceMethod="GetGLAccountList"
TargetControlID="txtExpenseGL"
>
</AjaxToolKit:AutoCompleteExtender>
<AjaxToolKit:ModalPopupExtender
ID="ModalPopupExtender1"
runat="server"
BackgroundCssClass="modalBackground"
CancelControlID="btnCancelCountry"
DropShadow="true"
PopupControlID="divExpenseGLSearch"
TargetControlID="imgbtnExpenseGL">
</AjaxToolKit:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>"
Thier two update panel like that having same code.
and This Grid Bind div Code:
<div id="divAccountGLSearch" class="popup" style="display: none; width: 350px;">
<table width="98%" align="center" border="0" cellpadding="0" cellspacing="0" style="height: 320px;">
<%-- For Heading and Image and CloseDiv --%>
<%-- Row 1 For Header Text --%>
<tr>
<th>
<h1>
List of Pre-Paid Account GL
</h1>
</th>
<td align="right" valign="top" style="padding-top: 6px;">
<img onclick="CloseDiv();" src="../../Images/close.gif" border="0" />
</tr>
<%-- Row 2 For Find TextBox and Find Button --%>
<tr>
<td class="form-label" style="padding-left: 5px;width:70%;">
Search
<asp:TextBox ID="txtFindPrePaidExpenses" runat="server" onBlur="javascript:setpopupfocus();" ></asp:TextBox>
</td>
<td align="left" style="width:30%;">
<table>
<tr>
<td>
<asp:LinkButton ID="btnFindCountry" CssClass="button" runat="server"
OnClientClick="ShowPopupAccGLSearch();" onclick="btnFindCountry_Click">
<span>Find</span></asp:LinkButton>
</td>
</tr>
</table>
</td>
</tr>
<%-- Row 3 For Repater Control --%>
<tr>
<td colspan="2" align="center">
<div style="overflow: auto; height: 280px; width: 100%;">
<asp:GridView ID="gvSearchAccountGL" runat="server" AutoGenerateColumns="False"
Width="98%" CssClass="table-grid" border="0" CellPadding="0"
CellSpacing="0" onrowdatabound="gvSearchAccountGL_RowDataBound"
>
<Columns>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:HiddenField ID="hfIndex" runat="server" Value='<%# Container.DataItemIndex + 1 %>'/>
</ItemTemplate>
<HeaderStyle HorizontalAlign="left" />
<ItemStyle HorizontalAlign="left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Account GL">
<ItemTemplate>
<asp:Label ID="lblAccountGLCode" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ACM_ACCOUNT_CODE")%>' ></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="left" />
<ItemStyle HorizontalAlign="left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Account Description">
<ItemTemplate>
<asp:Label ID="lblAccountGLDescription" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ACM_ACCOUNT_DESC")%>' ></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="left" />
<ItemStyle HorizontalAlign="left" />
</asp:TemplateField>
</Columns>
<RowStyle CssClass="gridRow" />
<HeaderStyle CssClass="gridHeader" />
<SelectedRowStyle BackColor ="Gray" />
</asp:GridView>
</div>
</td>
</tr>
<%-- Row 4 For Space Image --%>
<tr>
<td colspan="2">
<img src="../../Images/spacer.gif" border="0" class="seprator" />
</td>
</tr>
<%-- Row 5 For OK and Cancel Button --%>
<tr>
<td colspan="2">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>
<asp:LinkButton ID="btnOKPrePaidExpense" CssClass="button" runat="server"
onclick="btnOKPrePaidExpense_Click">
<span>OK</span></asp:LinkButton>
</td>
<td>
</td>
<td>
<asp:LinkButton ID="btnCancelPrePaidExpense" CssClass="button" runat="server">
<span>Cancel</span></asp:LinkButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
My div Bind Code is Out off Update Panel Code.
so how to stop postback and Stable Pop Control
Thank U
To prevent the ImageButton control from automatically posting back when it's clicked, your ShowPopupExpGLSearch() function should return false.