473,788 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding Dynamically Created DataGrid Controls

Hi Guys

I have a datagrid that are databound at runtime and columns are added automatically to it from the dataset. OnEdit Command renders all fields as editable, my problem is I need to specify in some way which columns are not editable, I have the columns I would like to lock for editing, but how do I tell the datagrid this ? My columns are dynamically added to the grid at runtime, because the dataset might be different everytime

Any help will be greatly appreciated

Regard
CJ Smit
Nov 18 '05 #1
3 1487
((BoundColumn)D ataGrid1.Column s[not edited column index]).ReadOnly = true;
HTH

"CJ Smit" <sm****@telkom. co.za> wrote in message
news:D9******** *************** ***********@mic rosoft.com...
Hi Guys,

I have a datagrid that are databound at runtime and columns are added automatically to it from the dataset. OnEdit Command renders all fields as
editable, my problem is I need to specify in some way which columns are not
editable, I have the columns I would like to lock for editing, but how do I
tell the datagrid this ? My columns are dynamically added to the grid at
runtime, because the dataset might be different everytime.
Any help will be greatly appreciated.

Regards
CJ Smit

Nov 18 '05 #2
Thanks Anatoly

Do you perhaps have some example code snippet for me

Much appreciated

Regard
CJ Smit
Nov 18 '05 #3
Hi Smit,

Thanks for your followup. I've checked and found that the attachement seems
only avaliable in OE client. Would you please check the message in OE? Any
way, I've post the page's code here in case that you may got any
difficulties using the OE client:

-------------------------------aspx
page-------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>BindGrid </title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<asp:DataGrid id="dgMain" runat="server" AutoGenerateCol umns="False">
<Columns>
<asp:BoundColum n DataField="inde x"
HeaderText="Ind ex"></asp:BoundColumn >
<asp:BoundColum n DataField="name "
HeaderText="Nam e"></asp:BoundColumn >
<asp:BoundColum n DataField="desc ription"
HeaderText="Des cription"></asp:BoundColumn >
<asp:EditComman dColumn ButtonType="Lin kButton" UpdateText="Upd ate"
HeaderText="Ope ration" CancelText="Can cel"
EditText="Edit" ></asp:EditCommand Column>
</Columns>
</asp:DataGrid></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</form>
</body>
</HTML>

---------------------------------code behind page
class----------------------------------
public class BindGrid : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Data Grid dgMain;

private void Page_Load(objec t sender, System.EventArg s e)
{
if(!IsPostBack)
{
Load_Data();
Bind_Data();

}
}

protected void Load_Data()
{
DataTable tb = new DataTable();
tb.Columns.Add( "index");
tb.Columns.Add( "name");
tb.Columns.Add( "descriptio n");

for(int i=1;i<=10;i++)
{
DataRow row = tb.NewRow();
row["index"] = i.ToString();
row["name"] = "Name" + i.ToString();
row["descriptio n"] = "Descriptio n" + i.ToString();
tb.Rows.Add(row );
}

Session["TEMP_DATA"] = tb;
}

protected void Bind_Data()
{
DataTable tb = (DataTable)Sess ion["TEMP_DATA"];
dgMain.DataSour ce = tb;
dgMain.DataBind ();
((BoundColumn)d gMain.Columns[0]).ReadOnly = true;
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
InitializeCompo nent();
base.OnInit(e);
}

private void InitializeCompo nent()
{
this.dgMain.Can celCommand += new
System.Web.UI.W ebControls.Data GridCommandEven tHandler(this.d gMain_CancelCom m
and);
this.dgMain.Edi tCommand += new
System.Web.UI.W ebControls.Data GridCommandEven tHandler(this.d gMain_EditComma n
d);
this.dgMain.Upd ateCommand += new
System.Web.UI.W ebControls.Data GridCommandEven tHandler(this.d gMain_UpdateCom m
and);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void dgMain_UpdateCo mmand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
dgMain.EditItem Index = -1;
Bind_Data();
}

private void dgMain_CancelCo mmand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
dgMain.EditItem Index = -1;
Bind_Data();
}

private void dgMain_EditComm and(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
dgMain.EditItem Index = e.Item.ItemInde x;
Bind_Data();
}
}

=============== =============== =============== ===

Please check it out and feel free to let me know if you still have any
problems on it.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #4

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

Similar topics

0
2474
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically added row it also removes the row at the end along with the added row. Plz tell me if, I am missing any thing. Code </asp:datagrid>
2
2035
by: Colin McGuigan | last post by:
This is a translation of an ASP page to ASP.Net. First, the background: The goal is to have a grid of different settings for the application -- think something along the lines of the Property Page for a control. You have two columns -- the first column is a simple caption, and the second column can be one of a number of controls (textbox, checkbox, dropdownlist, etc) for each row. So row #1 might have a textbox in the second column,...
2
2214
by: Quentin Huo | last post by:
Hi: I have a user control and I want to dynamically create a Label control and TextBox control when the button "add more author name" is clicked. I did like this: 1. there is a "PlaceHolder" control "ph" in the user control; 2. create a Label control and TextBox control when in the "add" button
2
3451
by: Tim_Mac | last post by:
hi, i have an aspx page which dynamically loads a user control and adds it to a placeholder. the control is recreated and added to the placeholder for postbacks as well. the user control contains a datagrid and some buttons and textboxes. the button events fire correctly and execute their code. however, the datagrid events fire a postback, and execute Page_load in the usercontrol, but the Item_Command code is not executed. the code to...
3
1847
by: david | last post by:
I have posted my question before. It seems that I can not find the solution. The question: I have datasource, say, ds which is bounded to a datagrid, dg. Assume that ds have 5 columns, c0,c1,c2,c3,c4. In some case, say, case 1, I want to display columns c0, c1,c2 in dg and use c3 and c4 in code behind. In case 2, I want to display column c0, c3, and c4, and use c1 and c2 in code behind. The following Possible solution do not work:
0
1351
by: news.zen.co.uk | last post by:
Hi Guys, Using VB .NET 2003 and ASP1.1, I have a Datagrid embedded in an ASP page. In the processing of the ItemDataBound event I dynamically create a new Datagrid control within the Cell of the Parent (this refelect GUI'wise a Parent Child related data). I also add Handlers to the sub datagrid using AddHandler to handle the EditCommandColumn as well as ItemDataBound. Parent Datagrid...
7
3574
by: rsaffy | last post by:
I am having trouble with my dynamically created button's event handling. I read that the buttons need to be recreated on every trip to the server, but how exactly do you do that when the datagrid the button is added to is created at run time? here is code from my aspx page... ------------------------------------------------------------------------------------- <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">...
0
2009
by: Silver Oak | last post by:
I have a DataGrid in which one of the columns is TemplateColumn that was created dynamically using iTemplate. I would like to have multi-row editing capability on the DataGrid. I'm trying to follow the example in MSDN http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp Section "Editing Multiple Rows at once". I would like to follow the second solution...
4
11012
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like to iterate thru the gridview's rows, examine the databound controls, then perform a database action. for some reason, i can't find the controls. i have a two templates: one that uses a label the other uses a textbox to display data. when the...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.