Gridview

gridview will not update does not give no error

GridView in ASP.NET will not update but it give no error. This took some 1+ hour of mine trying to resolve. I looked at this popular post but I could not find solution to my problem.

The problem in my case was the select statement.

The problem line was @IndID parameter, although my Gridview worked perfectly fine. I removed the where clause just for testing purpose and the update started function fine. So the problem is quite weird, select should not affect update operation but in this case it does!

Besides, also look into DataKeyNames parameter of gridview and set it to your primary key, usually ID field.

Looping through gridview in C# always return empty

I had a gridview which was bounded to a datasource (datatable in my case) in code behind in C#. Code was something like this

This was always returning empty (”) no matter which column index I was pointing to. I tried different variations like

but it failed too. After pondering on it for quite a while and still not resolved, I decided to loop through the data source itself, in my case a datatable. That actually worked! That code looks like this

I am still not sure why it will not read the values from GridView in a loop but at least there is work around.

One combined footer in GridView – ASP.NET

This link explains how to display the footer of a Gridview as one large cell rather than every cell has its own footer. I tried this solution but it did not work for me. I tweaked it and posted the correct one that worked for me.

Before you can actually use this code, make sure your set the Show Gridview property to true in Properties windows.

  1. Select your GridView, go to properties window, click on the lighting icon. Double click on the “RowCreated” event. It will create one if it is not already there and will directly take you there. If there was already one it will simply take you there.
  2. This should be the code in this new event

The advantage of the above code is

  1. It works
  2. It centers your text (link) in the middle of footer. You can add more styles if you like.