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

Top 5 Contributors of the Month
Imran Ghani
Sohaib Khalid
Post New Web Links

What object should I use - Gridview won't work

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

Hi All.

I would like to create a gridview that gets data from a datasource but doesn't display it in the normal fashion based on my table layout.


Table layout is:

Name     Emp#     Dept#     Booking Code#     AccessId

This is how it looks in the gridview but I would like it to look like:

Name:                     John Doe                               Dept#:                   12

Booking Code#:      1234                                     Booking Code#:     67


View Complete Post

More Related Resource Links

Updation in gridview using Ajax XmlHttp Object does't work



I have many divs in 1 page and each div consists of a gridview, the gridview is loaded by making AJax calls.

On load of the page, all the grid load data properly.

But now when i update any row in either of the grids, and make a call to the javascript that loads the grid in the page, it doesn't work rightly.

Any advices. Am i doing something wrong.

Wat are the options to update/refresh the grid.


RadioButton inside GridView, How to get it work as normal

Did you tried before to drag a RadioButton control inside a Gridivew templatefield, and then you attempt to select these RadioButtons , you will notice that the behavior of RadioButton control will be changed and it will work just like the behavior of checkbox control! the user will be able to select more than one radiobutton in the grid!

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

How to get object from the gridview selectindex changing Event.


I have a grid view which is populating with a data source through databind. And the Datasource is list of objects.Now when the user selected a row I want to get the object of that row.

I'm trying to get the row like this.


r = gvTruckCarrier.Rows[e.NewSelectedIndex];


drv = r.DataItem as DataRowView




but the drv value is

How to find specific nested object type in Gridview

Dears, I have a gridview with a nested placeholder in each rows. I nested some checkboxes in each placeholders in each rows dynamically, so their ServerIDs are not the same (I dont want to use nested gridview). at the end in a button event I want to count checked checkboxes in gridview while I can not use findcontrol() method in each rows to find checkboxes due to their different ServerIDs. How can I do this?

Problem in binding List<> object to Gridview



We I bind a list<> object to a gridview it calls an error like this:

Error: DataBinding: 'Default2+JobsList' does not contain a property with the name 'JobId'

Hear is my markup Codes:

<asp:GridView ID="GridView1" runat="server" DataKeyNames="JobId" AutoGenerateColumns="False"
                                <asp:BoundField DataField="JobName" .../>
                                <asp:BoundField DataField="JobExplain" .../>
                                <asp:ButtonField CommandName="DeleteJob" .../>

and Code behind:

public struct JobsList
        public int JobId;
        public string JobName, JobExplain;
        public JobsList(int id, string name, string explain)
            JobId = id;
            JobName = name;
            JobExplain = explain;

List<JobsList> list = new List<JobsList>();


list.Add(new JobsList(Approperiate Attributes..));
GridView1.DataSource = list;

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

Getting Access Denied when trying to work with PrintQueue object


I have client app that I am working on that is supposed to be able to manage print queues, such as resuming print jobs or purging jobs that have hung up.  The problem I am running in to is that I need to open the queue with appropriate rights to do that management.

I am using the line  below to create the queue.

pq = new PrintQueue(ps, printQueue, PrintSystemDesiredAccess.AdministratePrinter);

However, this line returns an access denied.  I am an admin on the local box, so I can't image why I am having this issue.

If I open the queue like this:

pq = new PrintQueue(ps, printQueue);

The open works find, but when I try to access the jobs in that queue, I get the access denied message.

Any idea what I am doing wrong here?  Any help would be greatly appreciated.


Joel WZ

Nested GridView Control returns "Object variable or With block variable not set" when outer GridView


Nested GridView Control returns "Object variable or With block variable not set" when outer GridView returns rows.

The Nested GridView Control works as long as the outer GridView returns rows, the following code works:


Protected Sub GridViewReport_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewReport.RowCreated

          If e.Row.RowType = DataControlRowType.DataRow Then

                 Dim myStatus_ID As SqlDataSource = CType(e.Row.FindControl("sqlDeviceStatusAssign"), SqlDataSource)
                 If Not e.Row.DataItem("Status_ID") Is Nothing Then
                                  myStatus_ID.SelectParameters(0).DefaultValue = e.Row.DataItem("Status_ID")
                 End If

       End If

update a list object with gridview


 How do you  Update a List(of Product) object with Gridview. i wish to  either increase/decrease the item field named Quantity.

GridView3.DataSource = Product


Gridview - Object Reference not set to an instance of an object - on rowupdated


I've already found the solution to this problem but I am posting here in case others bang their heads for too long before trying the simple fix. 

I have a gridview that on rowupdated I am capturing in a log the text from 2 columns.  What I tried was:

   Protected Sub IowaCompletedGrid_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles IowaCompletedGrid.RowUpdated
      Dim s As String = e.Keys("TaskID").ToString & ": " & e.Keys("Task").ToString

 End Sub

But that throws the 'Object reference not set to an instance of an object.' error.  Here's the weird part:  if you move the e.Keys("Task").ToString to it's own variable and then add them together, it works fine.

   Protected Sub IowaCompletedGrid_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles IowaCompletedGrid.RowUpdated
      Dim s As String = e.Keys("TaskID").ToString & ": "
      Dim sT As String = e.Keys("Task").ToString
      s = s & sT

' ...etc
 End Sub

my problem with all of this is why does it matter where I assign the e.Keys reference?  In my first examp

COM Object Interop DLL generated on Visual Studio 2010 does not work on 64-bit system



When I add a COM object Example.dll as reference, it will automatically generate a file called Interop.ExampleLib.dll to my bin folder. It works fine on 32-bit system but when I try it on a 64-bit my program fails to run.

I replaced the Interop.ExampleLib.dll with one that I generated a while ago using Visual Studio 2008, and it works on both 32 and 64-bit system.

Anyone knows what's the problem?

Thanks in advance!




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

GridView Edit-update don't work Delete does work


Can't tell what is wrong here . It worked fine and I didn't did anything special in code-behind 

I don't see any error  just the same data in gridview

" SelectCommand="SELECT [Date], [InitEmployee], [AmitName], [AgentcyName], [Broker], [MobileNumber], [TZ], [Reason], [CareDate], [Status], [Notes], [CareAgent] FROM [ClientsDmeiNihulRequests] ORDER BY [Date] DESC" ConflictDetection="OverwriteChanges" DeleteCommand="DELETE FROM [ClientsDmeiNihulRequests] WHERE [Date] = @original_Date AND [TZ] = @original_TZ AND (([InitEmployee] = @original_InitEmployee) OR ([InitEmployee] IS NULL AND @original_InitEmployee IS NULL)) AND (([AmitName] = @original_AmitName) OR ([AmitName] IS NULL AND @original_AmitName IS NULL)) AND (([AgentcyName] = @original_AgentcyName) OR ([AgentcyName] IS NULL AND @original_AgentcyName IS NULL)) AND (([Broker] = @original_Broker) OR ([Broker] IS NULL AND @original_Broker IS NULL)) AND (([MobileNumber] = @original_MobileNumber) OR ([MobileNumber] IS NULL AND @original_MobileNumber IS NULL)) AND (([Reason] = @original_Reason) OR ([Reason] IS NULL AND @original_Reason IS NULL)) AND (([CareDate] = @original_CareDate) OR ([CareDate] IS NULL AND @original_CareDate IS NULL)) AND (([Status] = @original_Status) OR ([Status] IS NULL AND @original_Status IS NULL)) AND (([Notes] = @original_Notes) OR ([Not

Bind gridview column to nested object



not really sure how to phrase this question.

If I have a list of contacts List<Contact> and a Contact object has an Office object property, I want to display a grid with columns

Contact Id, First Name, Last Name, Office Name

Where the sources of the above columns are respectively:

Contact.ContactId, Contact.FirstName, Contact.LastName, Contact.Office.OfficeName

I'm fine with binding the first 3, but was wondering whether I can bind the OfficeName using either Bind or Eval or whether I need to hook into the events and set the value there.






Inplace Edit in GridView

In this article I am presenting a different way to look at EditItemTemplate, using which user navigation for editing is reduced and . it looks very different (see screeen shots) then regular implementation of GridView.

GridView Confirmation Box Using JQuery BlockUI in asp.net

JQuery is the most popular JavaScript library. One of the main reasons for its fame is the plugin architecture. Anyone can create a separate library that leverage the JQuery library. In this article we are going to look at the BlockUI library which is used to block the user screen while performing a task.
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