Modifying gridview data on the fly?
-
I'm returning data from a sql query that populates a gridview however I want to modify what's displayed in 1 of the gridview columns based on whether or not a value returned in the sql query is null. Basically, if the value in a particular row of data is null, I want to return an imagebutton that says "Add". If the value is not null, I want to return an imagebutton that says "Edit". For example, something like this: if(SqlQuery.SqlRow(20).SqlColumn(4).Value = null) { gridView.gridRow(20).gridColumn(4).Value = "
"; } else { gridView.gridRow(20).gridColumn(4).Value = "
"; } Any idea how I can do this? Thanks. -goalie35
-
I'm returning data from a sql query that populates a gridview however I want to modify what's displayed in 1 of the gridview columns based on whether or not a value returned in the sql query is null. Basically, if the value in a particular row of data is null, I want to return an imagebutton that says "Add". If the value is not null, I want to return an imagebutton that says "Edit". For example, something like this: if(SqlQuery.SqlRow(20).SqlColumn(4).Value = null) { gridView.gridRow(20).gridColumn(4).Value = "
"; } else { gridView.gridRow(20).gridColumn(4).Value = "
"; } Any idea how I can do this? Thanks. -goalie35
There are many ways you can handle this, one that comes to mind is On the column where you want to add this functionality 1.- Make that column a template column, this will allow you to Add controls to the column anyway you want 2.- add an Image Button on the column 3.- On the tag look for the source property of the image button 4.- Add something like this
<asp:imageButton id=imgButton1 runat=server ImageSource="<%(Eval(Container.DataItem, 'Column'))'Add.jpg':'Edit.jpg'%>" />
About the property of the image I don't recall if it is Source or Image Source but you get the IdeaGreets! Joel