.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Listview code syntax help vs Gridview

Posted By:      Posted Date: October 19, 2010    Points: 0   Category :ASP.Net



Any one know how to resolve the below list code? Is there a listview row property or equivalent to gridview?


   For Each rowItem As ListViewrow In Listview1.Rows


View Complete Post

More Related Resource Links

GridView Code Suggestions



I have a gridview which displays data from a database.

Everything works fine, the thing is that I haven't come with a method to do the next thing:

The gridview displays something like this:

Client - Total - Percentage

Ex1      1000    20%

Ex2      2000    40%

Ex3      1000    20%

Ex4      500      10%

Ex5      500      10%

This data might vary depending on the month selected etc etc....

What I want to do is that the gridview kind of check its rows and start summing the percentaje, when it sums 80% I want to color the rows that sum the 80% to one specific color then the rest of the rows  leave them with the default color or change it too.

I'm thinking that I might be able to do that with the row data bound event, but I just can't find the answer to do it, I know how to iterate through the rows to sum the values but then how I can tell it to stop if it reaches 80% and color the rows that completed that 80%.

Another thing, the rows that complete this 80% of course have to be the ones with the greatest percentages. In the example above it would be Ex1, Ex2, Ex3. That 80% percent can

Manually coding controls such as gridview, listview, repeater, etc.


using vs2010 and .net 4

In my project I have a separate DAL built from class files that I'd like to use to store my code for CRUD operations against my database.

I'm having a hard time finding examples of how to code server controls like the gridview, listview, repeater etc., for CRUD operations manually, i.e., without a datasource control of some flavor.

I don't have any problem manually coding the referenced controls to get my data, but I do have problems when it comes to coding them to perform CRUD operations unless I use a datasource control. When I use the datasource controls CRUD operations seem to automagically appear out of nowhere after they're configured.

Can someone point me to some samples somewhere? Have I missed a section at MSDN?


Editmode on GridView inside of ListView

I have a listview and inside the listview I have a gridview.  I'm binding data to the listview, then on the listview itemdatabound I'm binding the gridview. I want to make the gridview editable so I have an edit template and an edit command button.  I have the event rowediting and inside there I set the edit index. Now normally I rebind the control and everything works.  But if I rebind this gridview, nothing happens. I can trace through the rowediting and everything is working.  It's setting the edit index, it goes through the databind and gets the right data and binds it to the control. What is happening?  Why isn't my rebound edit mode gridview showing up?

Datalist, Gridview or Listview

I am extremely new to ASP and just started learning. I want to know which is better between Datalist, Gridview or Listview if I need paging and sorting functionality? This is what I have so far.I've tried Datalist but I am having trouble with the paging portion. I've tried gridview and listview and got the paging to work but for some reason, when I click on Pg 2, it refreshes the search or something and what was shown on Pg 1 would appear again on Pg 2.Thanks in advance for your help.<asp:MultiView id="MultiView1" ActiveViewIndex="0" Runat="server">                        <asp:View ID="View1" runat="server">                        <asp:DataList ID="DataList1" runat="server" DataKeyField="ItemID"                         DataSourceID="SqlDataSourceImage1" Width="100%"                         HorizontalAlign=

disable autopostback of checkbox inside of GridView during SelectedIndexChanged of ListView

Hi, I hope my question is clear: I have a checkbox placed inside a gridview: <GridView><asp:TemplateField HeaderText="Driver">   <ItemTemplate>       <asp:CheckBox ID="CheckBoxDriver" AutoPostBack="true" OnCheckedChanged="GridView_Persons_SelectedIndexChanged" ValidationGroup='<%# Eval("ID") + "-" +((GridViewRow)Container).RowIndex %>' CssClass="CXDriver" runat="server" Checked='false' />   </ItemTemplate>       </GridView> For example: A listViewItem 1 has 3 drivers are checked, A listViewItem 2 has 2 drivers are checked. Therefore, if changing the selectedIndex of the list, the checkbox indexChanged event will be fired. How could I disable the autopostback of the checkbox during the listview item changed. Thanks in advance

Display UTF-8 code in GridView

Hi, I have a table in database, all table is utf-8 character set, one column is Italian another is Russian. I put as sqldatasource in a webform, correctly made the connection string. To show data from table i use GridView. Problem is that russian characters are not displayed correctly and some Italian characters, those with stress, for example "è" is not displayed correctly true. I put <globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/> in web.config file but no result and font selected for gridview is "Arial" Could you please help me? Best Regards     

Display the item in the ComboBox inside the ListView(GridView)

I have the below code used in binding the values to the ComboBox in GridView(ListView), please help me < ListView Margin="480,51,6,14" Name="grid1" ItemsSource="{Binding UserDetail}" IsSynchronizedWithCurrentItem="True" Width="389" Grid.Column="1" > <ListView.View> <GridView> <GridViewColumn Header="UserName" Width="120" DisplayMemberBinding="{Binding Path=WindowsUser}"/> <GridViewColumn Header="Role" Width="140"> <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox Name="Rolecombo" Width="120" ItemsSource="{Binding Path=UserDetail}" SelectedValue="{Binding PFR_Tbl_Role.Role}"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Active" x:Name="column" Width="100"> <GridViewColumn.CellTemplate> <DataTemplate> <Grid Width="{Binding ElementName=column,Path=Width}"> <CheckBox IsChecked="{Binding Active}" HorizontalAlignment="Center" /> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView>  </ListView.View> </ListView>

Passing Querystring Value into Gridview/Listview

I have a master-detail page consisting of a databound GridView and ListView. It's pretty standard - when you select a row in the GridView is shows up the ListView. The problem I'm running into is when I want to link to that page with a specific row pre-selected in both views. It seems like it should be easy enough, but I just can't figure it out. Currently, the ListView is connected to the GridView with a ControlParameter in the SelectCommand. Any assistance would be greatly appreciated. (Let me know if you need more info.)

Javascript code to copy specific cell of gridview row

Dears, I need a javascript code to copy the text content of a cell of a row in gridview. I have a button in each row that users click it and the text content a cell of that row should be copied in a textbox out of gridview

Is it possible to assign a tooltip to the rows of a GridView in a ListView?

On my VS 2010 WPF app, I've got a GridView within a ListView.  The user searches for some clients, and the clients that match the search are put into the list view.  I'm wondering if it is possible to bring up data that would be specific the the client that the user is hovering the mouse over, in a tooltip?  And if the answer is yes, how is that done?Rod

gridview find invisible row from code behind


hi all,

let me explain completly. I designed an gridview, header template i added one textbox and button if the user enter something on Txtbox and click button then based on input i show corresponding rows only, all other rowss will be hidded using Javascript like below

tblOrders.rows[CurrRow].style.display = 'none';

now im doing something on the Gridview_RowCommand event at this time the gridview got refreshed so that the hiden rows are visible, but i dont want to show the hidden(invisible) rows while rowcommand event fired. so, is there any way to solve this issue?

experts please help me to resolve this...........!

changing Asp.net Gridview's cell from Label to edit mode in code behined file


 Hi all,

In my asp.net application i'm using gridview to which i'm binding data dynamically by writing a select query in code behined file (all column's are autogenerated) now i want to change gridview cell to edit mode from label to textbox or dropdown on clicking of gridview's cell.How can i achive this in code behined file.

thanks in advance

change gridview itemtemplate cssclass from code-behind


I want to pgroammatically change the gridview ItemTemplate properties (mostly CSS Class)

<asp:GridView ID="gvSearchResults" GridLines="None" Width="700px" ShowHeader="False" AutoGenerateColumns="False" DataSourceID="XMLDS" runat="server"><Columns>
<ItemStyle CssClass="WHATEVER" />

So in the gridview rowdatabound event, I want to change the template based on the data for that specific row.

Apart from the data, how can I change the ItemTemplate CSS class for the current row via Code behind?

code SQL to populate gridview with multiple random list box selections, How to


I could use some help in coding a query.

I have a list box that allows for multiple selections (holding down the control key) the selection quantity is basically unlimited, but realistically should never be more than 50 to 100 items from the listing of about 3000 items.

I need to collect the list of selected items from the drop down list and retrieve each of their full records from the item master and populate a gridview.

Any help would be greatly appreciated.


Thanks again,



code behind - variables and gridview-selected data



I'm a newbie using VWD 2010 Express, asp.net 4.0.  

I'm also learning VB and C#.  I'm pretty lost, so please direct me. 

I'm trying to understand the code-behind behind gridview select/edit buttons.  I'm not sure whether I need to look for asp.net or VB/C# tutorials. 

   protected void ds_Selecting(object sender,SqlDataSourceSelectingEventArgs e)

Using above example, 
1. How do I access the user-selected row data from the gridview in the code-behind? 
2. What is 'sender' and 'e'? 

If there's a tutorial that explains these, please direct me.

Thank you!

Gridview row sometimes has to be selected twice for code to work


I'm using the code below to extract data from a gridview and populate it into textboxes for the days and two drop downs for Project and Category.

For some rows in the gridview everything but the category ddl populates correctly. If I click the row a second time the category ddl displays the correct category.

Can anyone tell me why I have to click twice for some rows? And how do I fix this?

Thank you

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    //// Get the currently selected row using the SelectedRow property.
    GridViewRow row = GridView1.SelectedRow;

    txtSunday.Text = (row.Cells[6].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtMonday.Text = (row.Cells[7].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtTuesday.Text = (row.Cells[8].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtWednesday.Text = (row.Cells[9].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtThursday.Text = (row.Cells[10].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtFriday.Text = (row.Cells[11].Controls[0] as DataBoundLiteralControl).Text.Trim();
    txtSaturday.Text = (row.Cells[12].Controls[0] as DataBoundLiteralControl).Text.Trim();

    // Set ProjectList ddl to Project in selected row
    if (ProjectList.Items.FindByText

Gridview within a Listview


Please, I need some help.


I am trying to use a Gridview (pirces) within a Listview (products) and have it working for read only. In the Listview_OnItemDataBound I load the data manually with the statements:

GridViewProductPrices.DataSource = GetDataSourcePrices();


This works fine, but when I press the edit button, the row does not get to editmode.

The problem I have why the edit command does not work is that this statement does not work: this.Rows[rowIndex].RowState = DataControlRowState.Edit;

Findcontrol does not find it either.


If I use a datasourceID in the ASPX then it works:

datasourceid = "SqldatasourcePrices" however I am unable to provide the product key to this datasoure for the Gridview (price).


How can I get the Gridview inside the Listview in edit mode? OR

How can I get the product key to the SqldatasourcePrices

Since the Gridview is inside the Listview, the findcontrol does not find the Gridview control and so I can not set it to edit.

After that is all working, how can I implement the insert?



Here are the details of the ASPX:


<asp:ListView ID="ListView.. ....



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend