.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

GridView Code Suggestions

Posted By:      Posted Date: August 24, 2010    Points: 0   Category :ASP.Net


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

View Complete Post

More Related Resource Links

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     

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

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

Listview code syntax help vs Gridview




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


Edit all cells within a particular column => Gridview (vb code)


Hi there,

I'm looking for a technique to edit a whole column (vertical) instead of a row (horizontal).
Suppose i have 10 rows en 5 columns (like in Excel), and i want to edit all digits from different students (rows) for test number 3 (column).

How can i do that?

Can someone help me out here?



How to code "If Gridview is empty/no row, then do sth"


How to code "If Gridview is empty/no row, then do sth"


Want to cancel edit mode of gridview in the code.


I have several places where I have a gridview and dataview set, and when I hit an edit button on the gridview it opens up the dataview.  

When I hit a cancel button fom the dataview I have this code that returns mew to the gridview:

        dvwUser.Visible = false;
        gvwUserList.Enabled = true;
        gvwUserList.Visible = true;


        dvwUser.Visible = false;


how to gridview template in code behind


my input is

     sql="SELECT a.ID, a.TGT, a.PAGEID, a.TESTCASE from qc"

    my function call is



                          GridCombox("Testcase" )

my output is

                           Gridview add a label with query data

                            Gridview add a Text with query data

                            Gridview add a DropDown with query data


SQL code to populate gridview with multiple random list box selections


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 could really use some help building the SQL statement to select the choosen record data. I think I have the selection list worked out by populating an array but I am not clear on how to build the SQL query.

Any help would be greatly appreciated.


Thanks again

Convert code for GridView to work in DetailsView


Can anyone help me out please ?  I want this code to work in a DetailsView -

protected void gvContacts_RowDataBound(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType.Equals(DataControlRowType.DataRow))
            DropDownList ddlGroupName = (DropDownList)e.Row.FindControl("ddlGroupName");
            Label lblGroupName = (Label)e.Row.FindControl("lblGroupName");
            lblGroupName.Text = ddlGroupName.SelectedItem.Text;
            ddlGroupName.Visible = false;

Thank you in advance

change this Datagid code to Gridview code



How can we change this code for use in Gridview

this code is for datagrid


private void gridPopup_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
                if (e.Item.DataItem != null)
                    e.Item.Attributes.Add("onmouseover", "ShowTooltip('" + 
                        DataBinder.Eval(e.Item.DataItem, "client_name").ToString() + "','" + 
                        DataBinder.Eval(e.Item.DataItem, "Address").ToString() + "','" + 
                        DataBinder.Eval(e.Item.DataItem, "CITY").ToString() + "','" + 
                        DataBinder.Eval(e.Item.DataItem, "STATE").ToString() + "', '" + 
                        DataBinder.Eval(e.Item.DataItem, "PHONE").ToString() + "','" + 
                        DataBinder.Eval(e.Item.DataItem, "FAX").ToString() + 


how to create a query in gridview selectcommand without the code behind for getting the system date.


how to query the system date in selectcommand in gridview without using the codebehind. using c# .net


my code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT * FROM tablename where date_today = <SYSTEMDATE>" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"  ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"

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