how-to add checkboxfield dynamically to gridview control

S

spitapps

I have a gridview declaratively added to my webform. This gridview
displays data from a stored procedure returned as a dataset. Once the
dataset has been modified slightly i bind it to my gridview control.
Now where and how would i go about adding a column to my gridview
dynamically that is a checkboxfield and is checked based on some
criteria i want to use. An example...

if
DataSet.Tables(0).Rows(i).Item("Discontinued").toString().Equals("yes")
then
checkboxfield is readonly and checked when displayed
next row from dataset

Here is my <Columns> section of my gridview control

<Columns>
<asp:BoundField
DataField="customerNumber" HeaderText="CustomerNumber" />
<asp:BoundField
DataField="address2" HeaderText="Attention" />
<asp:BoundField DataField="city"
HeaderText="City" />
<asp:BoundField DataField="state"
HeaderText="State" />
<asp:BoundField DataField="zipcode"
HeaderText="Zipcode" />
<asp:BoundField
DataField="distance" HeaderText="Distance" />
<asp:HyperLinkField Text="Customer
Info.." DataNavigateUrlFields="rowid" Target="_blank"
DataNavigateUrlFormatString="Products.aspx?id={0}" />
</Columns>

Thanks for any help regarding this in advance

Kyle Spitzer
 
B

Beemer Biker

spitapps said:
I have a gridview declaratively added to my webform. This gridview
displays data from a stored procedure returned as a dataset. Once the
dataset has been modified slightly i bind it to my gridview control.
Now where and how would i go about adding a column to my gridview
dynamically that is a checkboxfield and is checked based on some
criteria i want to use. An example...

In a similar situation I set up an empty panel as the only object in a
column template. At bind time I then looped thru the a variable (in the db)
that told me how many images to add to the panel. eg:
Panel thisPanel = (Panel)e.Row.FindControl("Panel4Spectrums");
for(i= etc
HtmlImage thisSpectrum = new (HtmlImage());
thisSpectrum.add ...etc..
thisSpectrum.Attributes.Add("onclick","return ...etc
thisPanel.Controls.Add(thisSpectrum)

You can also add a column and later drop it as in "ALTER table ADD COLUMN
"NewCo.lumnName" You can set up the column and make it invisible until you
want to show it

...hth..


--
=======================================================================
Beemer Biker joestateson at grandecom dot net
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
=======================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top