TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mayank Pandey
NA
47
5.8k
How to get all data of a row in ListView on Button click
Jul 21 2015 4:26 AM
Hi , I have a listview control with Click Button. I want that if i click on a button then it should get all the data of that row on the basis of Unique ID of that Selected Row. I want it via ListView Property. I have one other method , when i click on Button of any Selected Row then it gets ID of that row in ItemCommand Event of ListView and from here I can call Sql query to get all the columns value of that ID. But I want it without doing this. Kindly help me out. Here is my code below:--
<asp:ListView ID="ImagesList" runat="server"
DataKeyNames="ID"
GroupItemCount="3"
OnPagePropertiesChanging="ImagesList_PagePropertiesChanging" OnItemCommand="ImagesList_ItemCommand">
<EmptyDataTemplate>
No Images found.
</EmptyDataTemplate>
<LayoutTemplate>
<table>
<tr runat="server" id="groupPlaceholder" />
</table>
</LayoutTemplate>
<GroupTemplate>
<tr class="product-item">
<td runat="server" id="itemPlaceholder" />
</tr>
</GroupTemplate>
<ItemTemplate>
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="product-item">
<div class="pi-img-wrapper">
<asp:Image ID="Image1" runat="server"
AlternateText='<%# Eval("ServiceName") %>'
ImageUrl='<%# Eval("ServiceImage") %>' class="img-responsive" />
<div>
<a href='<%# Eval("ServiceImage") %>' class="btn btn-default fancybox-button">Zoom</a>
</div>
</div>
<h3><%--<a href="Item.aspx"><%#Eval("ImageTitle") %></a>--%>
<asp:LinkButton ID="lnkImgTitle" runat="server" Text='<%#Eval("ServiceName") %>' CommandName="ImgTitle" CommandArgument='<%#Eval("ServiceName") %>'></asp:LinkButton>
</h3>
<div class="pi-price"><%#Eval("SellingPrice") %></div>
<%-- <a href="Shopping_Cart.aspx" class="btn btn-default add2cart">Add to cart</a>--%>
<asp:Button ID="btnAddToCart" runat="server" Text="Add to cart" CommandName="AddToCart" CommandArgument='<%#Eval("ID") %>' class="btn btn-default add2cart" />
</div>
</div>
<%-- <td class="pi-img-wrapper">
<asp:Image ID="MyPicture" runat="server"
AlternateText='<%# Eval("ImageTitle") %>'
ImageUrl='<%# Eval("ImageUrl") %>' class="img-responsive"/>
</td>--%>
</ItemTemplate>
</asp:ListView>
protected void ImagesList_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "ImgTitle")
{
string shopname = e.CommandArgument.ToString();
Response.Redirect("Item.aspx?vid="+shopname);
}
if (e.CommandName == "AddToCart")
{
int id = Convert.ToInt32(e.CommandArgument);
DataRow[] dr = dt.Select("ID="+id);
// ServiceName,ServiceImage,SellingPrice,MRP
string serviceName = dr[1]["ServiceName"].ToString();
string serviceImage = dr[1]["ServiceImage"].ToString();
float sellingPrice = Convert.ToInt64(dr[1]["SellingPrice"].ToString());
float mrp = Convert.ToInt64(dr[1]["SellingPrice"].ToString());
Response.Redirect("Shopping_Cart.aspx");
}
int index = Convert.ToInt32(e.Item.DataItemIndex);
}
Reply
Answers (
0
)
Issues in Aspx Page
how to use windows control library in asp.net