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

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

Dynamic Grid Selected row style

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

Hi friends,I have some problem in creating dynamic gridview and setting the selected row border style to Dotted Other then Back color nothing is effecting in selected row style.The code part is bellow

 SqlConnection con = new SqlConnection("server=ADAPT31;database=maruttest;uid=sa;pwd=sa");

        SqlDataAdapter adp = new SqlDataAdapter("select * from addressbook", con);
        DataTable dt = new DataTable();

        GridView GD = new GridView();
        GD.ID = "GD";
        GD.AutoGenerateColumns = false;
        GD.ShowFooter = false;
        GD.BorderStyle = BorderStyle.Solid;
        GD.SelectedRowStyle.BorderStyle = BorderStyle.Dotted;
        GD.SelectedRowStyle.BorderColor = System.Drawing.Color.Blue;
        GD.SelectedRowStyle.BackColor = System.Drawing.Color.BlueViolet;
        GD.GridLines = GridLines.Horizontal;
        GD.BorderColor = System.Drawing.Color.CornflowerBlue;
        GD.BorderWidth = 5;
        BoundField bound = null;

        foreach (DataColumn dc in dt.Columns)
            bound = new BoundField();
            bound.DataField = dc.ColumnName;
            bound.HeaderText = dc.ColumnName;

View Complete Post

More Related Resource Links

ASP.NET 4.0 Menu Top Level selected item style


I want to apply a css class to the level 1 menu item (parent) when it or any or it's children are selected.

I've looked at MSDN documentation and any number of examples and walkthroughs but I haven't come up with a way of managing this. I was thinking something like this might work but the style is not being applied to the parent. To further complicate matters, if I try to apply a css style to StaticSelectedStyle it doesn't pick it up at all.

Menu Markup:

<StaticSelectedStyle  Font-Bold="True" ForeColor="#3333CC" />

Code Behind:

        protected void MenuItemClick_NavMenu(Object sender, MenuEventArgs e)


            MenuItem parentItem = e.Item.Parent;

            if (parentItem != null)


                parentItem.Selected = true;



stay with the selected position in Grid View

I've got one columns of check boxes in a GridView, when i select the checkbox entire record(75 columns) is poupulated into formfileds resided just below the gidview. The problem I'm having is that when i selelect 50th record of database(db have 100 recrds) the view state should be  on 50th record level but it is scroll over to the toplevel after selecting the checkbox, if user wants to select the 51st record again he scroll to that level.how can i over come this problem.

WPF Data Grid - set style based on value

Hello All,
I am using a DataGrid and want to set the background of the row to certain color based on value. Example
One of the columns is Time Taken. If the value is less than 5, then no change. If it's between 6 and 10 then yellow and if greater than 10, then red.
I am looking for "OnDataBound" event - don't see any.
I am looking for something like
foreach(Row row in DataGrid1.Rows).... <-- not there.
How do I do it?
I am new to all this...sorry if this looks like a stupid question.

Creating a pivot of a collection and displaying it in a databound grid with dynamic columns



I'm trying to create a pivot of some data that I have about translation.

Basically what I have now is a collection of "Translation" objects which look like that :

Public Class SystemText
  Inherits Entity

#Region "Private variables"
  Private _textCategory As String
  Private _textName As String
  Private _languageCode As String
  Private _description As String
#End Region

#Region "Properties"
  Public Overridable Property TextCategory() As String

How can i post a selected row in grid


Please help me

I have a gridview and i added a button field and converted into templateField

my code is like this

Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs)

        For Each row As GridViewRow In GridView1.Rows

            Dim lbl As Label = CType(row.FindControl("Libo"), Label)
            Label3.Text = lbl.Text


my problem is that label3 is displaying the last row  that s because i used for each row

I want label3.text to display the control "libo" but for the selected row

please help

treeview selected node font style does not change


Hi All,

I have a treeview and I am giving the node style in code behind.

Treeview design is as below:

<asp:TreeView ID="tvIARHierarchies" runat="server" NodeIndent="15" ShowExpandCollapse="true"
                                        ShowLines="True" Width="98%" OnSelectedNodeChanged="tvIARHierarchies_SelectedNodeChanged">
                                        <ParentNodeStyle Font-Bold="False" />
                                        <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />

Based on the rowsize entered on the text box, how to generate a dynamic grid view of that many row?


Hi, I have a text box.It is having 2 validation on it(Range validator and req field validator). Now,if I enter an integer within 0-8,just after gettting out of focus of the text box,I need to generate a grid which should contain exactly that many number of rows. Now,My question is: 1.How to capture that number entered in the text box and without any button click event,how to to generate the grid?I suppose,I need to write the code in one of the TextBox event.But,which one and how? Please help me as I am in urgent need.

Create a group from selected rows of grid




Let me see if I can explain what I am trying to do...


From a gridview a user would be able to select as many rows as they wanted and create a "custom group" ... that user group would then be available from a dropdown list for future selection. So next time they would just select the "custom group" from a dropdown list and the resulting datagrid would only have those rows that were originally selected.

So if I had a datagrid which had: empoyeeID, name, address, phone#, etc...

1. I select what ever rows I want
2. Create a name for the new custom group
3. Click a "save group" button ... this would save all the employeeID's from selected rows.
4. A dropdown list would then be updated with the new custom group ... ie, MIKE's GROUP
5. User could then select MIKE's GROUP from a dropdown list and work only with rows that were added to it.


Hope that makes sense.

Thanks in advance.


Can't style selected item in ListView when GridView is used

Below is a simple window that contains a ListView. Note that it is overriding the SystemColors.HighlightBrushKey to change the color of the selected item.
Works fine, unless  the ListView.View block is enabled, and a GridView is defined.

When that is done, the GridView seems to enforce its own idea of what the selected row should look like.

How can I style the selected row of a ListView using a GridView?

<Window x:Class="WpfApplication1.Window3"
    Title="Window3" Height="300" Width="300">


Dynamic Data GridView style in ie9 isssue


Today I uppgraded my browser to ie9 and run my DynamicData app I'm working on. Strange thing happened. Vertical lines on gridviews can't pick up

their border style (light blue color) from DDGridView class in Site.css.  They all have black color. Did someone experience this issue,any workaround?

It's only vertical gridlines, borders around the table and rowstyle td elements are light blue as it's supposed to be.

Style a grid in a DataGrid


Does anyone know how to style cell/row borders(i.e. separators) in a DataGrid?

Setting borders on DataGridCell and DataGridRow does not do the trick. It just adds a new inner border

I can style separators in ColumnHeaders but cannot find anything that can do the same in the grid itself



Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

Building a grouping Grid with GridView and ASP.NET AJAX toolkit CollapsiblePanel

I've posted an update to this post to apply on demand loading of Details data using ASP.NET AJAX PageMethods. I'm demonstrating the usage if CollapsiblePanelExtender client events on the new post. Check it out.

I admit, Matt Berseth is really inspiring me! Few days ago I pass through 2 of his great posts:

.Surrounding your Data Table and Dialog Controls with ComponentArt Styled Panels
.Building a Grouping Grid with the ASP.NET 3.5 LinqDataSource and ListView Controls
The first one is pure design tips one which I used for making good presentation of my demo here. The 2nd post is actually the idea.

Dynamic Data Templates in GridView ASP.NET 3.5

At a high level, Dynamic Data Templates can be seen as a system to very quickly build up a User Interface linked with the relevant data model, immediately enabling you to perform CRUD operations (Create, Read, Update, Delete) on the database using the specified data source. They provide a powerful method for building up these kinds of applications, and I'm going to focus on an overview of what Dynamic Data Templates actually are, and a few ways of customizing them to suit industry needs.

ASP.NET repeater control - databind with style

even used the inline editing features, which I at the time thought was the coolest way possible to write ASP.NET code ( I managed to write code to hide all other rows and only show the current one - the row being edited). With a nice looking EditTemplate it looked indeed very slick but it really turned into giant and hard to manage code behind files.

ASP.NET 4.0 Dynamic Data and Many to Many Entity Framework Entities

I did not play much with Dynamic Data controls in VS2008 and just made a cool discovery in VS2010 Beta 2. This may not even be new, but as I'm sitting 30,000+ feet over the Atlantic ocean, I don't have access to VS2008 at the moment to check.

A Simple and Extensible Radio Button Style GridView

The GridView is one of the significant controls in ASP.NET 2.0 and later versions. No doubt it reduces a lot of work time. However, customizing the GridView control is not an easy task. For example, it's hard to add a radio button column to the GridView. This article demonstrates the reason why a radio button column cannot act as normal and how to create a simple and extensible radio button GridView.
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