DataGrid + BoundColumn + UpdateCommand

N

niki

Hello.
I have a problem with custom columns inside the datagrid.
I've set up a datagrid that populates from a database; I can edit the
datagrid values and update the db, so that's ok.
(btw, it's not as easy as the book claims...)

Now I'd like to format some columns, say date values, and what's more,
I'd like to make some columns not visible and some read-only.
I thought BoundColumn could be the solution, but as I create columns
this way and invoke the updatecommand event, the datagrid has no more
columns.
Inside the updatecommand event, the datagrid has just 1 column, I guess
it's the button one...

I've search this ng for some advice, but I couldn't understand how it
can be done.

Can you help me?

Thanks :)
 
G

Guest

Hi Niki,

You can use BoundCloumns and set Visible, ReadOnly properties for the
BoundCloumns like follows.:

<asp:datagrid id="datagrid" runat="server">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn Visible="False" DataField="ID" ></asp:BoundColumn>
<asp:BoundColumn DataField="FieldName" ReadOnly="True" HeaderText="Filed
Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Edid_FieldName" HeaderText="Filed
Name"></asp:BoundColumn>
....

</Columns>
</asp:datagrid>

Updatecommand event is trggered by clicking Update button. You can get data
by e.Item.Cells[col_index].Text.

HTH

Elton Wang
(e-mail address removed)



:
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top