473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DataGrid: set ReadOnly property at runtime?


Is it possible to set DataGrid's ReadOnly property to True/False at runtime?
An example:

<asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="id" ReadOnly="True"
HeaderText="ID"></asp:BoundColumn>
</Columns>
<asp:datagrid>
Jun 6 '06 #1
5 2164
Is it possible to set DataGrid's ReadOnly property to True/False at
runtime?


P.S. My question was not limited to <asp:BoundColumn/>, but to
<asp:TemplateColumn/> as well:

<asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False">
<Columns>
<ItemTemplate>
<asp:Label id="lblSum" runat="server" Text='<%#
Container.DataItem("Sum") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtSum" runat="server" Text='<%#
Container.DataItem("Sum") %>'>
</asp:TextBox>
</EditItemTemplate>
</Columns>
</asp:datagrid>

I would like to acomplish next: to show TextBoxes, only in some cells
(columns), not in all.
Jun 6 '06 #2
John Smith wrote:
Is it possible to set DataGrid's ReadOnly property to True/False at
runtime? An example:

<asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="id" ReadOnly="True"
HeaderText="ID"></asp:BoundColumn>
</Columns>
<asp:datagrid>


Hmm. You asked about the grid's ReadOnly property, but you illustrated
it by showing a column's ReadOnly attribute. Which one did you really
mean?

Sub SetGridEditMode(RO as boolean)
dg1.ReadOnly = RO
End Sub

or

Sub SetGridColEditMode(colidx as int32,RO as boolean)
dim col as datagridcolumn = dg1.Columns(colidx)
End Sub

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 6 '06 #3
Hmm. You asked about the grid's ReadOnly property, but you illustrated
it by showing a column's ReadOnly attribute. Which one did you really
mean?
Column's ReadOnly attribute.
Sub SetGridColEditMode(colidx as int32,RO as boolean)
dim col as datagridcolumn = dg1.Columns(colidx)
End Sub


Column doesn't have ReadOnly attribute/property?
Jun 6 '06 #4
John Smith wrote:
Is it possible to set DataGrid's ReadOnly property to True/False at
runtime?
P.S. My question was not limited to <asp:BoundColumn/>, but to
<asp:TemplateColumn/> as well:


My previous answer applies.

<snip>
I would like to acomplish next: to show TextBoxes, only in some cells
(columns), not in all.


If I understand the question correctly, you will need to use templates.
http://msdn.microsoft.com/msdnmag/issues/02/01/cutting/

http://msdn.microsoft.com/library/en...asp?frame=true
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 6 '06 #5
John Smith wrote:
Hmm. You asked about the grid's ReadOnly property, but you
illustrated it by showing a column's ReadOnly attribute. Which one
did you really mean?


Column's ReadOnly attribute.
Sub SetGridColEditMode(colidx as int32,RO as boolean)
dim col as datagridcolumn = dg1.Columns(colidx)
End Sub


Column doesn't have ReadOnly attribute/property?


You're right. I also missed a step:

dim col as boundcolumn = ctype(dg1.Columns(colidx), _
boundcolumn)
col.readonly = RO

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 6 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
0
by: Richard Ryerson | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls (watch...
4
by: Steve | last post by:
I am fairly new to VB.NET, and I am rewriting an application I wrote a while back, also in VB.NET. I aplied some new things I learned. Anyway, here is my problem....... I have a custom DataGrid...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.