Category Archives: DataPager

DataPager

UpdateProgress and the combination of a ListView with Modalpopupextender and Confirmbuttonextender

The UpdateProgress does not show when I’m using the combination of a ListView with Modalpopupextender and Confirmbuttonextender.

I want the UpdateProgress to show when I’m clicking the OKcontrolid button. And this is working fine:

<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:modalpopupextender id="Modalpopupextender1" runat="server" cancelcontrolid="ButtonDeleteCancel" okcontrolid="ButtonDeleleOkay" targetcontrolid="Button1" popupcontrolid="DivDeleteConfirmation" backgroundcssclass="ModalPopupBG" />
<asp:confirmbuttonextender id="Confirmbuttonextender1" runat="server" targetcontrolid="Button1" enabled="True" displaymodalpopupid="Modalpopupextender1" />

The page does it’s ClientSide magic with showing the PopUp, and when I click the OK button, the UpdateProgress starts fine.

As soon as I put it in a ListView ItemTemplate it does not work. The PopUp shows, but when I click on the OK button, the UpdateProgress does not show.

<asp:ListView runat="server" id="gwUnitInfo" GroupItemCount="1" DataSourceID="sqlUserRoles">
     <LayoutTemplate>
          <table class="gridview_TemplateComputer">
          <tr ID="groupPlaceholder" runat="server"></tr>
          </table> 
    </LayoutTemplate>
    <GroupTemplate>
         <tr id="productRow">
         <td ID="itemPlaceholder" runat="server"></td>
         </tr>
    </GroupTemplate>
    <itemtemplate>  
    <td class="cssItemLabel">
       <asp:Button ID="Button1" runat="server" Text="Button" />
       <asp:modalpopupextender id="Modalpopupextender1" runat="server" cancelcontrolid="ButtonDeleteCancel" okcontrolid="ButtonDeleleOkay" targetcontrolid="Button1" popupcontrolid="DivDeleteConfirmation" backgroundcssclass="ModalPopupBG" />
       <asp:confirmbuttonextender id="Confirmbuttonextender1" runat="server" targetcontrolid="Button1" enabled="True" displaymodalpopupid="Modalpopupextender1" />                            
    </td>                           
    </itemtemplate>
</asp:ListView>

Is there anyone who has seen the same thing? Is it a bug? and most important is there a whay I can solve this?

Thx for any reply :)

Lars

 

Hi,

This is an old post but I’m having a similar problem, so if you or anybody can provide some explanation or help I would appreciate.

I’m using a ListView and UpdateProgress works fine but if I define QueryStringField property in DataPager the updateProgress stops showing?! I wonder if it is a bug or if it get’s disabled for any reason.

Thanks.

You can refer this to show ModalPopup as an AJAX Progress Indicator

http://mattberseth.com/blog/2007/07/modalpopup_as_an_ajax_progress.html

[RESOLVED]padding not working in <tr>

Had no problem in the master page setup where the main content is placed inside a <td>.

The ListView page is placed in the main content and I have some css for the <tr> as follows:

tr.lvLayoutRow
{
    background-color: #D1B5A1;
    vertical-align: top;
    padding-top: 3px;
    padding-bottom: 3px;
}

the background color works and the alignment works but for some reason the padding is not working.  The ListView is nested inside the inner table and the DataPager inside the outer table.  They do this so the Pager works with the listview.  Here is the code for tables:

    <LayoutTemplate>
        <table id="Table1" runat="server" width="100%">
            <tr id="Tr1" runat="server">
                <td id="Td1" runat="server">
                    <table ID="itemPlaceholderContainer" runat="server" border="1" style="border-collapse: collapse; border-color: #5C4033; border-style: solid; width: 100%;">
                        <tr id="Tr3" runat="server" class="lvLayoutRow">
                            <td id="Th1" runat="server" style="min-width: 135px;">Actions</td>
                            <td id="Th2" runat="server" style="width: 100%;">Discussions</td>
                            <td id="Th3" runat="server" style="min-width: 60px;">Topics</td>
                            <td id="Th4" runat="server" style="min-width: 50px;">Posts</td>
                            <td id="Th5" runat="server" style="min-width: 100px;">User</td>
                            <td id="Th6" runat="server" style="min-width: 150px;">Last Topic</td>
                        </tr>
                        <tr ID="itemPlaceholder" runat="server">
                        </tr>
                    </table>
                </td>
            </tr>
            <tr id="Tr6" runat="server">
                <td id="Td2" runat="server" style="text-align: left;">
                    <asp:DataPager ID="DataPager1" runat="server" PageSize="5">
                        <Fields>
                            <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" ShowLastPageButton="True" />
                        </Fields>
                    </asp:DataPager>
                </td>
            </tr>
        </table>
    </LayoutTemplate>

Any ideas as to why the padding isn’t working?

Apply your padding to the td element instead of tr.

You can not apply CSS padding to table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column elements.

Yeah. apply css on td instead of tr like the following

tr.lvLayoutRow td
{
    background-color: #D1B5A1;
    vertical-align: top;
    padding-top: 3px;
    padding-bottom: 3px;
}

try this

.lvLayoutRow
{
    background-color: #D1B5A1;
    vertical-align: top;
    padding-top: 3px;
    padding-bottom: 3px;
}
    <LayoutTemplate>
       
<table id="Table1" runat="server" width="100%">
           
<tr id="Tr1" runat="server">
               
<td id="Td1" runat="server">
                   
<table ID="itemPlaceholderContainer" runat="server" border="1" style="border-collapse: collapse; border-color: #5C4033; border-style: solid; width: 100%;">
                       
<tr id="Tr3" runat="server">
                           
<td id="Th1" class="lvLayoutRow" runat="server" style="min-width: 135px;">Actions</td>
                           
<td id="Th2" class="lvLayoutRow" runat="server" style="width: 100%;">Discussions</td>
                           
<td id="Th3" class="lvLayoutRow" runat="server" style="min-width: 60px;">Topics</td>
                           
<td id="Th4" class="lvLayoutRow" runat="server" style="min-width: 50px;">Posts</td>
                           
<td id="Th5" class="lvLayoutRow" runat="server" style="min-width: 100px;">User</td>
                           
<td id="Th6" class="lvLayoutRow" runat="server" style="min-width: 150px;">Last Topic</td>
                       
</tr>
                       
<tr ID="itemPlaceholder" runat="server">
                       
</tr>
                   
</table>
               
</td>
           
</tr>
           
<tr id="Tr6" runat="server">
               
<td id="Td2" runat="server" style="text-align: left;">
                   
<asp:DataPager ID="DataPager1" runat="server" PageSize="5">
                       
<Fields>
                           
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" ShowLastPageButton="True" />
                       
</Fields>
                   
</asp:DataPager>
               
</td>
           
</tr>
       
</table>
   
</LayoutTemplate>

Only the TD can have padding

pnoneal, 

This may be caused due to 3 scenarios:

1: One way you need to check is that, you must specify the entire css parent hirearchy if you are using child elements using a .

eg: #Table1 #Tr1  #itemPlaceholderContainer tr.lvLayoutRow


2: Use Margin property instead of padding

3: Use

padding-top: 3px !important; 
 padding-bottom: 3px !important;
Coz, this may occur as the padding property may get overriden by the parent's padding property. Use !important value to override base value with parent's.
For more details visit: mithunondotnet.wordpress.com

I tried all of them.  The [!important] didn’t work.  The tr.lvLayoutRow td from
protienshow did work.  Putting the class in each <td> worked too.  But if I’m going to do that I might as well use different class names so that I can set the width for each column too.  I’m tyrying
to take out all the layout information and put into a theme so I guess I’ll go with the seperate class for each <td>.  Just makes more work.

I don’t know I’m undecided.  The method that
protienshow
 provided is smooth.  Maybe, I’ll just leave the style for the <td> inline with the code.  I’ve taken out most of the layout and put into .css file.  At least I have some options.

Thanks,

Paul

res.web

<div class="comment-left-col">

<input id="quote-createdby" value="res.web" type="hidden" /></div> <div class="comment-right-col">

Re: padding not working in

4/20/2012 4:46:34 AM

<div id="reference-post-content" class="reply-comment">

try this        .lvLayoutRow

</div> </div>

It worked when I put td.lvLayoutRow instead of just lvLayoutRow.

Hi

Multiple jQuery in One Page

hi 
i tried to make this slideshow works, but all my of my efforts failed, could you please help me with that!
http://www.om-it.net/en/ 
i tried to add these lines

<script type="text/javascript">
         var slides = $.noConflict(true);
</script>

i am using this script http://slidesjs.com/examples/standard/ 
thank you very much


I’ve not needed to do this myself, but from what I’ve looked into it seems that
RequireJS is the current approach for including multiple versions of jQuery on the same page.

Actually you are totally right it is multiple versions of jQuery, and i tried to make it works but still failing.

Okay, here what i did, i removed the other jQuery scripts, and made a  listview using datapager for the latest news insted of the news slider code, and also removed the fancybox for the more details in the Offers scetion, but still slideshow not working,
could you please help me with that?

thank you very much

hello again,

Finally, slideshow works but with there are some issues, i hope you can help me to fix it.

<div>i copied the same script to my arabic section (http://www.om-it.net/ar), and i noticed that slideshow is not working in the arabic section although it is working in the English section, beside the pagination looks so weird.  </div> <div>thank you very
much</div>

Server side counterpart for CSS 3 browser size detection?

I’m building a website to take into account the device size.  I’m using CSS3′s @media tag to change the webpages appropriately as the viewport size changes.  I also have a listview control to display products.  I would like to be able to dynamically set
the number of items per page and the number of items in each group as the viewport changes.  Is this possible?

Hi,

see this building windows 8 blog post…

http://blogs.msdn.com/b/b8/archive/2012/03/21/scaling-to-different-screens.aspx

- all done client side with css 3 and html5

I would argue that the exception is Smart Phones where you need a completely different site navigation pattern and layout targeted to a 320px by 480px screen size and scaled to 1.

see m.bing.com or m.seek.com.au – mobile optimized sites that don’t use server side UAS sniffing.

aslo see this excellent article

http://sixrevisions.com/web_design/a-guide-on-layout-types-in-web-design/

of the layout types discussed there are two versions… fixed and fluid… only a fluid layout will scale to fit all screen sizes…. you adjust the scaling in a device viewing a web page with the viewport meta tag….and using the HTML5 document type declaration.

Regards.

The size is not sent to the server, you could sniff the nrowser type on the server and send down different pages. Plenty of code examples on the net available for that.

Eric

Hi,

I totally agree with Eric. An (not so easy) approach would be to create a flexible layout (because of line breakings) and let the user choose how many entries he would like to see on one page (like you see on many sites).

I’m sorry.  Due to illness in the family I had to put this aside for awhile.

I do have a fluid layout, and I can certainly let the user select how many items to display, but this is where I run into a problem. 

I’m using a listview control.  At the moment I have it set to dsiplay three records across.  However I’d like to let the listview display however many records across it can handle.  I can easily do this with CSS.  My problem is I think it looks bad to allow
say, 10 records per page, and display 4 records across.  You get three rows of 4, 4, and 2 records on every page but the last.  I’m looking for a way to update my datapager server side so that each row of each page is full, as long as I have enough records.

[RESOLVED]Problem in paging

I used a data pager in my application,this shows the <a> tags for paging which is under a span tag, and the name of span tag is the name of the datapage which i given it at .aspx page.

Now my problem is i want to stop _doPostBack function of javascript and use my own function i use the follwing line for that

$("span['id*='Pager1] a").bind(‘click’, function() {

var pageId = $(this).text();

//some code here

return false;
});

But this function not work,i dont understand what is problem

 

Code is correct …it would work for html like this  <span id="Pager1"><a>1</a></span>, check generated html to see if it is same. Make sure you write it inside $(document).ready(function(){}); I tested it at my end and its working fine…obviously i replaced
var pageId = $(this).text() with alert($(this).text());

Thanks

My html is as follows

<span id="ctl00_CPHPackage_Pager1"><span>1</span>&nbsp;<a href="javascript:__doPostBack('ctl00$CPHPackage$Pager1$ctl00$ctl01','')">2</a>&nbsp;

<a href="javascript:__doPostBack('ctl00$CPHPackage$Pager1$ctl00$ctl02','')">3</a>&nbsp;

<a href="javascript:__doPostBack('ctl00$CPHPackage$Pager1$ctl00$ctl03','')">4</a>&nbsp;

<a href="javascript:__doPostBack('ctl00$CPHPackage$Pager1$ctl00$ctl04','')">5</a>&nbsp;&nbsp;

<a href="javascript:__doPostBack('ctl00$CPHPackage$Pager1$ctl00$ctl05','')">...</a>&nbsp;

</span>

Now my problem is it works first time correctly,but when i click second time on this paging ,then my my jquery function is not called and postback occurs

if you have registered the function in document.ready…it should not cause problem if it is normal postback (I assume you are not using updatepanel)…and i dont understand the __doPostBack in href ?? 

Thanks

Actualy i use Jquery Load Function to load data and the data it load contains paging by datapager therefore __doPostBack comes in href,actually my problem is solved now i using live in place of bind…

Thanks for your support,if you have some comments on that then i feel pleasured

I would have suggestedt to use "live" if you were using updatepanel….partial postback unregisters the event you write using jquery and recreates the DOM …."live" attaches event for those newly created DOM elements.

http://api.jquery.com/live/

Thanks

[RESOLVED]datapager only works on the second click

HI,

So i am creating a datapager for my listview, but i can only advance pages on second click

What’s wrong on my code?

.aspx file

<asp:ListView ID="list" runat="server" ItemPlaceholderID="itemPlaceholder" >
                <LayoutTemplate>
                    <ul>
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                    </ul>

                    <asp:DataPager ID="pager" runat="server" PagedControlID="list"
                        PageSize="5" OnPreRender="DataPager_PreRender">
                        <Fields>
                            <asp:NumericPagerField PreviousPageText="<--" NextPageText="-->" />
                        </Fields>
                    </asp:DataPager>

                </LayoutTemplate>

                <ItemSeparatorTemplate>
                    <hr />
                </ItemSeparatorTemplate>
                <ItemTemplate>
                    <li class="cnnews">
                        <div style="display: inline;">
                            <div style='float: right;'><b><%# Eval("date_news")%></b></div>
                            <br></br>

                            <asp:HyperLink ID="lbltitle_news" runat="server" CssClass="link3" Font-Size="16" Text='<%# Eval("title_news")%>'
                                NavigateUrl='<%# "~/News.aspx?idnews=" + (int)Eval("id_news") %>'></asp:HyperLink>

                        </div>
                        <br />
                        <asp:Label ID="lblresume_news" runat="server"><%# Eval("title_news")%></asp:Label>

                    </li>
                </ItemTemplate>
                <EmptyItemTemplate>
                    <li>No data Found
                    </li>
                </EmptyItemTemplate>
            </asp:ListView>

here’s my code behind code

protected void Page_Load(object sender, EventArgs e)
{
            if (!IsPostBack)
            {
                BindListViewControls();
}
}

        
protected void DataPager_PreRender(object sender, EventArgs e)
{
BindListViewControls();
}

Thanks!

I would suggest you to use AspNetPager rather using pager.

You can easily design it. It has more option than Pager and do efficient paging. You just need to pass counter and set few basic setting than it start working

See Demo site

Thanks Guys. I solved the problem i need to add

<asp:ListView ID="list" runat="server" ItemPlaceholderID="itemPlaceholder"
OnPagePropertiesChanging="list_PagePropertiesChanging">

and now works fine ;)

[RESOLVED]Custome Control Pageing ?

I have Create datapager( in custome cotrol  (User Control)

i have need comman control just drag and drop with stored procedure with pageing

hi jayrajgiri ,

From what I understand you want to add command control with stored procedure with paging. 

Your main purpose is to call a stored procedure via the control. 

I would suggest you to read the reference below for more information: 

 ASP.Net GridView using SQL Server Stored Procedure: 

Custom Paging in ASP.Net GridView using SQL Server Stored Procedure  

How to do custom paging: 

.Need to customize you store procedure 

.Change in binding Gridview or DataList or Repeater whatever you are using 

.Need to populate ( Generate ) Pager (Pagination ) manually ( Code also given below). 

Custom paging in asp.net using stored procedure in gridview    

 I hope it helps you.

[RESOLVED]ListView error on update: Object must implement IConvertible

I am a beginner in asp.net. I have listView where I try to update SQL Server data by means of a stored procedure. I use VS2010 and a local SQL Server 2008 R2. There is no code behind (no C# code).

The update from listview works perfectly when I make the update with traditional update statement from ListView:   UpdateCommand="UPDATE Hour SET TheHours = @TheHours WHERE (TheHoursID = @TheHoursID)"

But when I try to do the same thing (update same fields) with stored procedure I get the following error:"Object must implement IConvertible". The stored procedure is tested and does the job perfectly when tested on SQL Server.This error appears when I introduce
EditItemTemplate for one or more parameters  in html asp code in VS2010.   I miss something basic here. I am very confused by the fact that the update works perfectly in one case, but not with stored procedure.  What could be wrong?

I have tried to change datatype in SQL Server table from decimal(18,4) to float, no effect.

 

Regards

 

<asp:SqlDataSource ID="SqlDataTestStoored" runat="server"
            ConnectionString="<%$ ConnectionStrings:HoursConnectionString %>"
            SelectCommand="Hours_testSelect" SelectCommandType="StoredProcedure"
            UpdateCommand="Hours_testUpdate" UpdateCommandType="StoredProcedure"
            ondatabinding="ListView1_SelectedIndexChanged">
            <UpdateParameters>
                <asp:ControlParameter ControlID="ListView1" Name="TheHours"
                    PropertyName="EditItemTemplate" Type="Decimal" DefaultValue="5"  />
                <asp:ControlParameter ControlID="ListView1" Name="TheHoursID"
                    PropertyName="EditItemTemplate" Type="Int32" DefaultValue="" />
                <asp:ControlParameter ControlID="ListView1" Name="ActivityID"
                    PropertyName="EditItemTemplate" Type="Int32"  />
            </UpdateParameters>
        </asp:SqlDataSource>

Here is stored procedure:

ALTER

PROCEDURE [dbo].[Hours_testUpdate] 

– Add the parameters for the stored procedure here

@TheHours

as
decimal(18,4),
@TheHoursID
int,
@ActivityID
int

AS

BEGIN

Update
Hour

Set TheHours
= @TheHours

where TheHoursID
= @TheHoursID

END

Use parameter instead of ControlParameter. Like : <asp:Parameter Name="TheHours" Type="Decimal" DefaultValue="5" /> then bind the control property like Text=’<%# Bind("TheHours") %>’ for textbox text property inside edit/insert template. Set also ListView DataKeyNames
= "ActivityId"

Then I get empty parameter values in the procedure call. Here is what SQL Profiler gives me for the procedure call:

exec Hours_testUpdate @TheHours = NULL, @ActivityID = NULL, @TheHoursID = 8

Regards

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestStoredProc.aspx.cs" Inherits="TestStoredProc_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ListView ID="ListView1" runat="server" DataKeyNames="TheHoursID"
            DataSourceID="SqlDataTestStoored"
            onselectedindexchanged="ListView1_SelectedIndexChanged"
            onload="ListView1_Load">
            <AlternatingItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    </td>
                    <td>
                        <asp:Label ID="TheHoursIDLabel" runat="server"
                            Text='<%# Eval("TheHoursID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="TheHoursLabel" runat="server" Text='<%# Eval("TheHours") %>' />
                    </td>
                    <td>
                        <asp:Label ID="TheDateLabel" runat="server" Text='<%# Eval("TheDate") %>' />
                    </td>
                    <td>
                        <asp:Label ID="ActivityIDLabel" runat="server"
                            Text='<%# Eval("ActivityID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="InvoiceIDLabel" runat="server" Text='<%# Eval("InvoiceID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <EditItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="UpdateButton" runat="server" CommandName="Update"
                            Text="Update" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
                            Text="Cancel" />
                    </td>
                    <td>
                        <asp:Label ID="TheHoursIDLabel1" runat="server"
                            Text='<%# Eval("TheHoursID") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="TheHoursTextBox" runat="server"
                            Text='<%# Eval("TheHours") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="TheDateTextBox" runat="server" Text='<%# Eval("TheDate") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="ActivityIDTextBox" runat="server"
                            Text='<%# Eval("ActivityID") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="InvoiceIDTextBox" runat="server"
                            Text='<%# Eval("InvoiceID") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="UserIDTextBox" runat="server" Text='<%# Eval("UserID") %>' />
                    </td>
                </tr>
            </EditItemTemplate>
            <EmptyDataTemplate>
                <table runat="server" style="">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <InsertItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="InsertButton" runat="server" CommandName="Insert"
                            Text="Insert" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
                            Text="Clear" />
                    </td>
                    <td>
                        &nbsp;</td>
                    <td>
                        <asp:TextBox ID="TheHoursTextBox" runat="server"
                            Text='<%# Eval("TheHours") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="TheDateTextBox" runat="server" Text='<%# Eval("TheDate") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="ActivityIDTextBox" runat="server"
                            Text='<%# Eval("ActivityID") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="InvoiceIDTextBox" runat="server"
                            Text='<%# Eval("InvoiceID") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="UserIDTextBox" runat="server" Text='<%# Eval("UserID") %>' />
                    </td>
                </tr>
            </InsertItemTemplate>
            <ItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    </td>
                    <td>
                        <asp:Label ID="TheHoursIDLabel" runat="server"
                            Text='<%# Eval("TheHoursID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="TheHoursLabel" runat="server" Text='<%# Eval("TheHours") %>' />
                    </td>
                    <td>
                        <asp:Label ID="TheDateLabel" runat="server" Text='<%# Eval("TheDate") %>' />
                    </td>
                    <td>
                        <asp:Label ID="ActivityIDLabel" runat="server"
                            Text='<%# Eval("ActivityID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="InvoiceIDLabel" runat="server" Text='<%# Eval("InvoiceID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
                    </td>
                </tr>
            </ItemTemplate>
            <LayoutTemplate>
                <table runat="server">
                    <tr runat="server">
                        <td runat="server">
                            <table ID="itemPlaceholderContainer" runat="server" border="0" style="">
                                <tr runat="server" style="">
                                    <th runat="server">
                                    </th>
                                    <th runat="server">
                                        TheHoursID</th>
                                    <th runat="server">
                                        TheHours</th>
                                    <th runat="server">
                                        TheDate</th>
                                    <th runat="server">
                                        ActivityID</th>
                                    <th runat="server">
                                        InvoiceID</th>
                                    <th runat="server">
                                        UserID</th>
                                </tr>
                                <tr ID="itemPlaceholder" runat="server">
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr runat="server">
                        <td runat="server" style="">
                            <asp:DataPager ID="DataPager1" runat="server">
                                <Fields>
                                    <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
                                        ShowLastPageButton="True" />
                                </Fields>
                            </asp:DataPager>
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    </td>
                    <td>
                        <asp:Label ID="TheHoursIDLabel" runat="server"
                            Text='<%# Eval("TheHoursID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="TheHoursLabel" runat="server" Text='<%# Eval("TheHours") %>' />
                    </td>
                    <td>
                        <asp:Label ID="TheDateLabel" runat="server" Text='<%# Eval("TheDate") %>' />
                    </td>
                    <td>
                        <asp:Label ID="ActivityIDLabel" runat="server"
                            Text='<%# Eval("ActivityID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="InvoiceIDLabel" runat="server" Text='<%# Eval("InvoiceID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
                    </td>
                </tr>
            </SelectedItemTemplate>
        </asp:ListView>
        <asp:SqlDataSource ID="SqlDataTestStoored" runat="server"
            ConnectionString="<%$ ConnectionStrings:HoursConnectionString %>"
            SelectCommand="Hours_testSelect" SelectCommandType="StoredProcedure"
            UpdateCommand="Hours_testUpdate" UpdateCommandType="StoredProcedure"
            ondatabinding="ListView1_SelectedIndexChanged">
            <UpdateParameters>
                <asp:Parameter  Name="TheHours" Type="Decimal" />
                <asp:Parameter  Name="TheHoursID" Type="Int32"  />
                <asp:Parameter  Name="ActivityID" Type="Int32"  />
                <asp:Parameter Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    
    </div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    </form>
</body>
</html>
Use two way binding (Bind) to pass value for updating instead one way binding (Eval).

Thanks, it worked.

Regards

[RESOLVED]How to Query Data from GridView

Dear All,

I had link  DB with Gridview, May i know how to query it when i text in data in textbox or select in dropdownlist ?

asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
        <AlternatingItemTemplate>
            <tr style="background-color:white;">
                <td>
                    <asp:Label ID="DATELabel" runat="server" Text='<%# Eval("DATE") %>' />
                </td>
                <td>
                    <asp:Label ID="ITEMLabel" runat="server" Text='<%# Eval("ITEM") %>' />
                </td>
                <td>
                    <asp:Label ID="ITEM_TYPELabel" runat="server" Text='<%# Eval("ITEM_TYPE") %>' />
                </td>
                <td>
                    <asp:Label ID="DESCRIPTIONLabel" runat="server"
                        Text='<%# Eval("DESCRIPTION") %>' />
                </td>
                <td>
                    <asp:Label ID="MATERIALLabel" runat="server" Text='<%# Eval("MATERIAL") %>' />
                </td>
                <td>
                    <asp:Label ID="NET_WEIGHTLabel" runat="server"
                        Text='<%# Eval("NET_WEIGHT") %>' />
                </td>
                <td>
                    <asp:Label ID="VENDOR_NAMELabel" runat="server"
                        Text='<%# Eval("VENDOR_NAME") %>' />
                </td>
                <td>
                    <asp:Label ID="REASONCODELabel" runat="server"
                        Text='<%# Eval("REASONCODE") %>' />
                </td>
                <td>
                    <asp:Label ID="LOCATORLabel" runat="server" Text='<%# Eval("LOCATOR") %>' />
                </td>
                <td>
                    <asp:Label ID="CONTAINER_SOURCELabel" runat="server"
                        Text='<%# Eval("CONTAINER_SOURCE") %>' />
                </td>
                <td>
                    <asp:Label ID="CONTAINER_TYPELabel" runat="server"
                        Text='<%# Eval("CONTAINER_TYPE") %>' />
                </td>
                <td>
                    <asp:Label ID="CONTAINER_QTYLabel" runat="server"
                        Text='<%# Eval("CONTAINER_QTY") %>' />
                </td>
                <td>
                    <asp:Label ID="STATUSLabel" runat="server" Text='<%# Eval("STATUS") %>' />
                </td>
                <td>
                    <asp:Label ID="DOCNUMLabel" runat="server" Text='<%# Eval("DOCNUM") %>' />
                </td>
                <td>
                    <asp:Label ID="REMARKLabel" runat="server" Text='<%# Eval("REMARK") %>' />
                </td>
                <td>
                    <asp:Label ID="CREATEUSERLabel" runat="server"
                        Text='<%# Eval("CREATEUSER") %>' />
                </td>
                <td>
                    <asp:Label ID="CREATEDATELabel" runat="server"
                        Text='<%# Eval("CREATEDATE") %>' />
                </td>
            </tr>
        </AlternatingItemTemplate>
        <EditItemTemplate>
            <tr style="background-color:White;color: #284775;">
                <td>
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update"
                        Text="Update" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
                        Text="Cancel" />
                </td>
                <td>
                    <asp:TextBox ID="DATETextBox" runat="server" Text='<%# Bind("DATE") %>' />
                </td>
                <td>
                    <asp:TextBox ID="ITEMTextBox" runat="server" Text='<%# Bind("ITEM") %>' />
                </td>
                <td>
                    <asp:TextBox ID="ITEM_TYPETextBox" runat="server"
                        Text='<%# Bind("ITEM_TYPE") %>' />
                </td>
                <td>
                    <asp:TextBox ID="DESCRIPTIONTextBox" runat="server"
                        Text='<%# Bind("DESCRIPTION") %>' />
                </td>
                <td>
                    <asp:TextBox ID="MATERIALTextBox" runat="server"
                        Text='<%# Bind("MATERIAL") %>' />
                </td>
                <td>
                    <asp:TextBox ID="NET_WEIGHTTextBox" runat="server"
                        Text='<%# Bind("NET_WEIGHT") %>' />
                </td>
                <td>
                    <asp:TextBox ID="VENDOR_NAMETextBox" runat="server"
                        Text='<%# Bind("VENDOR_NAME") %>' />
                </td>
                <td>
                    <asp:TextBox ID="REASONCODETextBox" runat="server"
                        Text='<%# Bind("REASONCODE") %>' />
                </td>
                <td>
                    <asp:TextBox ID="LOCATORTextBox" runat="server" Text='<%# Bind("LOCATOR") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CONTAINER_SOURCETextBox" runat="server"
                        Text='<%# Bind("CONTAINER_SOURCE") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CONTAINER_TYPETextBox" runat="server"
                        Text='<%# Bind("CONTAINER_TYPE") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CONTAINER_QTYTextBox" runat="server"
                        Text='<%# Bind("CONTAINER_QTY") %>' />
                </td>
                <td>
                    <asp:TextBox ID="STATUSTextBox" runat="server" Text='<%# Bind("STATUS") %>' />
                </td>
                <td>
                    <asp:TextBox ID="DOCNUMTextBox" runat="server" Text='<%# Bind("DOCNUM") %>' />
                </td>
                <td>
                    <asp:TextBox ID="REMARKTextBox" runat="server" Text='<%# Bind("REMARK") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CREATEUSERTextBox" runat="server"
                        Text='<%# Bind("CREATEUSER") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CREATEDATETextBox" runat="server"
                        Text='<%# Bind("CREATEDATE") %>' />
                </td>
            </tr>
        </EditItemTemplate>
        <EmptyDataTemplate>
            <table runat="server"
                style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
                <tr>
                    <td>
                        No data was returned.</td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert"
                        Text="Insert" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
                        Text="Clear" />
                </td>
                <td>
                    <asp:TextBox ID="DATETextBox" runat="server" Text='<%# Bind("DATE") %>' />
                </td>
                <td>
                    <asp:TextBox ID="ITEMTextBox" runat="server" Text='<%# Bind("ITEM") %>' />
                </td>
                <td>
                    <asp:TextBox ID="ITEM_TYPETextBox" runat="server"
                        Text='<%# Bind("ITEM_TYPE") %>' />
                </td>
                <td>
                    <asp:TextBox ID="DESCRIPTIONTextBox" runat="server"
                        Text='<%# Bind("DESCRIPTION") %>' />
                </td>
                <td>
                    <asp:TextBox ID="MATERIALTextBox" runat="server"
                        Text='<%# Bind("MATERIAL") %>' />
                </td>
                <td>
                    <asp:TextBox ID="NET_WEIGHTTextBox" runat="server"
                        Text='<%# Bind("NET_WEIGHT") %>' />
                </td>
                <td>
                    <asp:TextBox ID="VENDOR_NAMETextBox" runat="server"
                        Text='<%# Bind("VENDOR_NAME") %>' />
                </td>
                <td>
                    <asp:TextBox ID="REASONCODETextBox" runat="server"
                        Text='<%# Bind("REASONCODE") %>' />
                </td>
                <td>
                    <asp:TextBox ID="LOCATORTextBox" runat="server" Text='<%# Bind("LOCATOR") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CONTAINER_SOURCETextBox" runat="server"
                        Text='<%# Bind("CONTAINER_SOURCE") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CONTAINER_TYPETextBox" runat="server"
                        Text='<%# Bind("CONTAINER_TYPE") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CONTAINER_QTYTextBox" runat="server"
                        Text='<%# Bind("CONTAINER_QTY") %>' />
                </td>
                <td>
                    <asp:TextBox ID="STATUSTextBox" runat="server" Text='<%# Bind("STATUS") %>' />
                </td>
                <td>
                    <asp:TextBox ID="DOCNUMTextBox" runat="server" Text='<%# Bind("DOCNUM") %>' />
                </td>
                <td>
                    <asp:TextBox ID="REMARKTextBox" runat="server" Text='<%# Bind("REMARK") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CREATEUSERTextBox" runat="server"
                        Text='<%# Bind("CREATEUSER") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CREATEDATETextBox" runat="server"
                        Text='<%# Bind("CREATEDATE") %>' />
                </td>
            </tr>
        </InsertItemTemplate>
        <ItemTemplate>
            <tr style="background-color:#DCDCDC;color: #000000;">
                <td>
                    <asp:Label ID="DATELabel" runat="server" Text='<%# Eval("DATE") %>' />
                </td>
                <td>
                    <asp:Label ID="ITEMLabel" runat="server" Text='<%# Eval("ITEM") %>' />
                </td>
                <td>
                    <asp:Label ID="ITEM_TYPELabel" runat="server" Text='<%# Eval("ITEM_TYPE") %>' />
                </td>
                <td>
                    <asp:Label ID="DESCRIPTIONLabel" runat="server"
                        Text='<%# Eval("DESCRIPTION") %>' />
                </td>
                <td>
                    <asp:Label ID="MATERIALLabel" runat="server" Text='<%# Eval("MATERIAL") %>' />
                </td>
                <td>
                    <asp:Label ID="NET_WEIGHTLabel" runat="server"
                        Text='<%# Eval("NET_WEIGHT") %>' />
                </td>
                <td>
                    <asp:Label ID="VENDOR_NAMELabel" runat="server"
                        Text='<%# Eval("VENDOR_NAME") %>' />
                </td>
                <td>
                    <asp:Label ID="REASONCODELabel" runat="server"
                        Text='<%# Eval("REASONCODE") %>' />
                </td>
                <td>
                    <asp:Label ID="LOCATORLabel" runat="server" Text='<%# Eval("LOCATOR") %>' />
                </td>
                <td>
                    <asp:Label ID="CONTAINER_SOURCELabel" runat="server"
                        Text='<%# Eval("CONTAINER_SOURCE") %>' />
                </td>
                <td>
                    <asp:Label ID="CONTAINER_TYPELabel" runat="server"
                        Text='<%# Eval("CONTAINER_TYPE") %>' />
                </td>
                <td>
                    <asp:Label ID="CONTAINER_QTYLabel" runat="server"
                        Text='<%# Eval("CONTAINER_QTY") %>' />
                </td>
                <td>
                    <asp:Label ID="STATUSLabel" runat="server" Text='<%# Eval("STATUS") %>' />
                </td>
                <td>
                    <asp:Label ID="DOCNUMLabel" runat="server" Text='<%# Eval("DOCNUM") %>' />
                </td>
                <td>
                    <asp:Label ID="REMARKLabel" runat="server" Text='<%# Eval("REMARK") %>' />
                </td>
                <td>
                    <asp:Label ID="CREATEUSERLabel" runat="server"
                        Text='<%# Eval("CREATEUSER") %>' />
                </td>
                <td>
                    <asp:Label ID="CREATEDATELabel" runat="server"
                        Text='<%# Eval("CREATEDATE") %>' />
                </td>
            </tr>
        </ItemTemplate>
        <LayoutTemplate>
            <table runat="server">
                <tr runat="server">
                    <td runat="server">
                        <table ID="itemPlaceholderContainer" runat="server" border="1"
                            style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                            <tr runat="server" style="background-color:#DCDCDC;color: #000000;">
                                <th runat="server">
                                    DATE</th>
                                <th runat="server">
                                    ITEM</th>
                                <th runat="server">
                                    ITEM_TYPE</th>
                                <th runat="server">
                                    DESCRIPTION</th>
                                <th runat="server">
                                    MATERIAL</th>
                                <th runat="server">
                                    NET_WEIGHT</th>
                                <th runat="server">
                                    VENDOR_NAME</th>
                                <th runat="server">
                                    REASONCODE</th>
                                <th runat="server">
                                    LOCATOR</th>
                                <th runat="server">
                                    CONTAINER_SOURCE</th>
                                <th runat="server">
                                    CONTAINER_TYPE</th>
                                <th runat="server">
                                    CONTAINER_QTY</th>
                                <th runat="server">
                                    STATUS</th>
                                <th runat="server">
                                    DOCNUM</th>
                                <th runat="server">
                                    REMARK</th>
                                <th runat="server">
                                    CREATEUSER</th>
                                <th runat="server">
                                    CREATEDATE</th>
                            </tr>
                            <tr ID="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr runat="server">
                    <td runat="server"
                        style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
                        <asp:DataPager ID="DataPager1" runat="server">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
                                    ShowLastPageButton="True" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        <SelectedItemTemplate>
            <tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
                <td>
                    <asp:Label ID="DATELabel" runat="server" Text='<%# Eval("DATE") %>' />
                </td>
                <td>
                    <asp:Label ID="ITEMLabel" runat="server" Text='<%# Eval("ITEM") %>' />
                </td>
                <td>
                    <asp:Label ID="ITEM_TYPELabel" runat="server" Text='<%# Eval("ITEM_TYPE") %>' />
                </td>
                <td>
                    <asp:Label ID="DESCRIPTIONLabel" runat="server"
                        Text='<%# Eval("DESCRIPTION") %>' />
                </td>
                <td>
                    <asp:Label ID="MATERIALLabel" runat="server" Text='<%# Eval("MATERIAL") %>' />
                </td>
                <td>
                    <asp:Label ID="NET_WEIGHTLabel" runat="server"
                        Text='<%# Eval("NET_WEIGHT") %>' />
                </td>
                <td>
                    <asp:Label ID="VENDOR_NAMELabel" runat="server"
                        Text='<%# Eval("VENDOR_NAME") %>' />
                </td>
                <td>
                    <asp:Label ID="REASONCODELabel" runat="server"
                        Text='<%# Eval("REASONCODE") %>' />
                </td>
                <td>
                    <asp:Label ID="LOCATORLabel" runat="server" Text='<%# Eval("LOCATOR") %>' />
                </td>
                <td>
                    <asp:Label ID="CONTAINER_SOURCELabel" runat="server"
                        Text='<%# Eval("CONTAINER_SOURCE") %>' />
                </td>
                <td>
                    <asp:Label ID="CONTAINER_TYPELabel" runat="server"
                        Text='<%# Eval("CONTAINER_TYPE") %>' />
                </td>
                <td>
                    <asp:Label ID="CONTAINER_QTYLabel" runat="server"
                        Text='<%# Eval("CONTAINER_QTY") %>' />
                </td>
                <td>
                    <asp:Label ID="STATUSLabel" runat="server" Text='<%# Eval("STATUS") %>' />
                </td>
                <td>
                    <asp:Label ID="DOCNUMLabel" runat="server" Text='<%# Eval("DOCNUM") %>' />
                </td>
                <td>
                    <asp:Label ID="REMARKLabel" runat="server" Text='<%# Eval("REMARK") %>' />
                </td>
                <td>
                    <asp:Label ID="CREATEUSERLabel" runat="server"
                        Text='<%# Eval("CREATEUSER") %>' />
                </td>
                <td>
                    <asp:Label ID="CREATEDATELabel" runat="server"
                        Text='<%# Eval("CREATEDATE") %>' />
                </td>
            </tr>
        </SelectedItemTemplate>
    </asp:ListView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:CIMProRPT01ConnectionString %>"
        SelectCommand="SELECT [DATE], [ITEM], [ITEM_TYPE], [DESCRIPTION], [MATERIAL], [NET_WEIGHT], [VENDOR_NAME], [REASONCODE], [LOCATOR], [CONTAINER_SOURCE], [CONTAINER_TYPE], [CONTAINER_QTY], [STATUS], [DOCNUM], [REMARK], [CREATEUSER], [CREATEDATE] FROM [WM_TRANS_HISTORY]">
    </asp:SqlDataSource>
    <br />
    <br />
    <br />

</asp:Content>

Hi caulson,

From my understanding, you would like to query data to bind GridView by SqlDataSource.

If so, please try to refer to the following code:

In the aspx file:

<asp:TextBox runat="server" ID="txtSearch" AutoPostBack="true"></asp:TextBox>
        <asp:Button runat="server" Text="Click" />
        <asp:GridView runat="server" DataSourceID="SqlDataSource1"></asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:Demo01ConnectionString %>"
            DeleteCommand="DELETE FROM [Student] WHERE [Id] = @Id"
            InsertCommand="INSERT INTO [Student] ([Id], [name], [sex]) VALUES (@Id, @name, @sex)"
            SelectCommand="SELECT * FROM [Student] where name=@name" UpdateCommand="UPDATE [Student] SET [name] = @name, [sex] = @sex WHERE [Id] = @Id">
            <SelectParameters>
                <asp:ControlParameter ControlID="txtSearch" DbType="String" Name="name" PropertyName="Text"  />
            </SelectParameters>
        </asp:SqlDataSource>

Hope it can help you, if there have anything unclear, please let me know.

Best Regards,
Terry Guo

ListView OnSelectedIndexChanging event on client side

Can we write OnSelectedIndexChanging event on client side for ListView using Java script, please provide some help.

It depends… What triggers the selectedindexchanged?

On Click it triggers the OnSelectedIndexChanging event

I understand on click, but on click of what?

Hi Anunay,

According to your description, my understanding is that you would like to use
Javascript
to trigger the SelectedChanged event of ListView.

If so, please try using __doPostBackplease(‘’,’’) to trigger the event, and about the parameter of the methond, we can according to your DataPager ID to generate it, please try to refer to the following code:

In the aspx file:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ListViewPage.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ListView ID="ListView1" runat="server" OnPagePropertiesChanging="ListView1_PagePropertiesChanging">
        <LayoutTemplate>
            <ul>
                <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
            </ul>
        </LayoutTemplate>
        <ItemTemplate>
            <li>
                <%# Eval("Name") %> (<%# Eval("Currency") %> <%# Eval("Price") %>)
            </li>
        </ItemTemplate>
        <EmptyDataTemplate>
            No data
        </EmptyDataTemplate>
        </asp:ListView>
<asp:DataPager ID="lvDataPager1" runat="server" PagedControlID="ListView1" PageSize="5">
            <Fields>
                <asp:NumericPagerField ButtonType="Link" />
            </Fields>
        </asp:DataPager>
        <input type="button" onclick="__doPostBack('lvDataPager1$ctl00$ctl00', '');" value="previous" />
        <input type="button" onclick="__doPostBack('lvDataPager1$ctl00$ctl01', '');" value="next" />
        
    </div>
    </form>
</body>
</html>

In the asp.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ListViewPage
{
    public partial class WebForm1 : System.Web.UI.Page
    {
       protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindListView();
            }
        }

        void BindListView()
        {
            ListView1.DataSource = SampleData();
            ListView1.DataBind();
        }
        List<Product> SampleData()
        {
            List<Product> p = new List<Product>();
            p.Add(new Product() { Name = "Microsoft Windows 7", Price = 70, Currency = "USD" });
            p.Add(new Product() { Name = "HP ProBook", Price = 320, Currency = "USD" });
            p.Add(new Product() { Name = "Microsoft Office Home", Price = 60, Currency = "USD" });
            p.Add(new Product() { Name = "NOKIA N900", Price = 350, Currency = "USD" });
            p.Add(new Product() { Name = "BlackBerry Storm", Price = 100, Currency = "USD" });
            p.Add(new Product() { Name = "Apple iPhone", Price = 400, Currency = "USD" });
            p.Add(new Product() { Name = "HTC myTouch", Price = 200, Currency = "USD" });
            return p;
        }
        protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            //set current page startindex, max rows and rebind to false
            lvDataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);

            //rebind List View
            BindListView();
        }
    }
}

In the Product.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ListViewPage
{
    public class Product
    {
        public string Name { get; set; }
        public decimal Price { get; set; }
        public string Currency { get; set; }
    }
}

Hope it can help you.

If there is anything unclear, please let me know.

Best Regards,
Terry Guo

Thanks Terry for you helpful reply, however please try to understand my problem below:

I have used ListView to populate List from Database and it should have selection changed event raised after changing the selected list item in the list. Below is the code:

   <asp:ListView ID="GroupList" runat="server" OnSelectedIndexChanging="GroupList_SelectedIndexChanging" ItemType="Group">
            <ItemTemplate>
                <li>
                    <asp:LinkButton runat="server" ID="LinkItem" Text=’<%#Item.Name%>’ CommandName="Select" CommandArgument=’<%#Item.Id%>’></asp:LinkButton>
                </li>
            </ItemTemplate>
            <SelectedItemTemplate>
                <li id="selectedItem">
                    <asp:LinkButton runat="server" ID="LinkItem" Text=’<%#Item.Name%>’ CommandName="Select" CommandArgument=’<%#Item.Id%>’ CssClass="active"></asp:LinkButton>
                </li>
            </SelectedItemTemplate>
        </asp:ListView>
   

Problem is I do not want to use LinkButton to avoid postback on each click for selection changed , could you please tell some other way to populate List other than ListView or LinkButton

and issue with LinkButton it does postback everytime and thus binds the listview everytime it does postback for that resolution i need help.

What is the purpose of selecting an item?  Are you doing any processing on it?

Yes, on the basis of selected item I want to display some other fields in other TextBlock controls.