Code snippet of the day : Resizing ASP.NET Datagrid Controls in Edit mode at runtime
2004-06-10 01:34
766 查看
By default, the control that is provided in a DataGrid's Edit Mode is the TextBox control, unless of course you are using EditItemTemplates, which is left for another discussion. In Edit mode, the TextBox is pretty wide. What if you want to make it narrower? Change the font with a stylesheet? Set it so it can only be a certain length? By coding the DataGrid's PreRender event, you can accomplish all this, and anything else you want to do, with your control. This example gets the textbox control located in the datagrid's second cell, then sets its Width and Maxlength properties respectively. Simply access the control via the ordinal number of the cell that contains it, cast it to your desired control, then modify its properties like normal.
Hope this is just what you want
1private void DataGrid1_PreRender(object sender, System.EventArgs e) 2{ 3 if (DataGrid1.EditItemIndex > -1) 4 { 5 TextBox objTextBox = DataGrid1.Items[DataGrid1.EditItemIndex]. 6 Cells[1].Controls[0] as TextBox; 7 objTextBox.Width = Unit.Parse("50px"); 8 } 9}
Hope this is just what you want
相关文章推荐
- Code snippet of the day : persist the scroll position of an ASP.NET page
- An Overview Of The New Services, Controls, And Features In ASP.NET 2.0
- Usage of the @ (at) sign in ASP.NET
- Code snippet of the day : Get Chinese Spell in C#
- Code snippet of the day : Exporting DataGrid Data to Excel...
- flex/in the datagrid,how to get the new value of cell in the datagrid after edit
- .NET Business Connector mode assembly is built against version 'v2.0.50727' of the runtime
- Atlas Control Toolkit and Source Code for the Build-in Asp.Net 2.0 Providers
- /*程序员面试宝典*/Which of the following statements describe the results of executing the code snippet below in C++?
- The process was terminated due to an internal error in the .NET Runtime at IP 7915EE73 (79140000) wi
- Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additio
- It is not possible to run two different versions of ASP.NET in the same IIS process:IIS
- Question 15: Which of the following statements describe the results of executing the code snippet below in C++?
- In Search Of ASP.Net Controls
- Fw:Managing View State in ASP.NET 4 Using the New ViewStateMode Property
- Running multiple versions of the Framework in ASP.NET
- Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application (9 of 10)
- DropDownList Controls In an ASP.Net DataGrid
- It is not possible to run two different versions of ASP.NET in the same IIS process
- Source Code for the Built-in ASP.NET 2.0 Providers Now Available for Download !