Forms Data Controls :: Set A TableCell Object To Have Width=20%?
Jan 17, 2011
I am dynamically building a table and I need to set the first column to have a width of 20% of the table width. Below is a part of the code I'm using.
trHead1 = New TableRow
trHead1.CssClass = "BillCalcHead"
tcCalc = New TableCell
tcCalc.CssClass = "YesBorder"
tcCalc.Text = "Rates"
trHead1.Cells.Add(tcCalc)
tcCalc = New TableCell
tcCalc.CssClass = "YesBorder"
tcCalc.Text = "Month"
trHead1.Cells.Add(tcCalc)
If I add tcCalc.Width="20%" I get the error that 20% can't be converted to an integer. If i try to set a style with tcCalc.Style="width:20%" it tells me that syle is read only. How do I do this?
I am having a bit of trouble trying to get teh postback data from a programmatic generated radio buttons in TableCell object. I have the following ASP user control:
I generate the TableRow and TableCell base off XML data file. When the submit occurs I can not access the data values from the radio buttons that are generated. I try to get the data in the following manner:
I'm rewriting my website in aspx to pull text from a SQl server and pop it up in a modal. I have everything working fine, but when I was using plain asp and HTML tables, I was able to format some of the text in the database using HTML tags, and they would render to screen. Is there anyway to do the same thing when using the following:
I have a dropdown list in a gridview field. The DataValueField for the ddl is an 8 digit item code. The text to display through will be quite longer, 40-60 characters because it will combine the item code and item name into a single string. I don't want the dropdownlist field to be that wide though, only what is displayed when the ddl is selected.In Access you can set the width property of the list to display wider than the field itself. Is there that capability in ASP.NET and if so where do I find it?
Is there any way to set the width of a GridView to a pre-determined width?
I have set the width of the gridview and all the columns to a % and then to a number of pixels but it does work. The gridview always sets itself to a width required to display all fields and it goes beyond the resolution of the screen. I would like to contain it to 1024 pixels.
I'm having difficulty trying to create and persist controls inside of a gridview during postbacks. I have an unbound Datagrid control which is created with x number of rows and y number of columns during the Page_Load event.
[Code]....
During the RowDataBound event of the GridView, I create a placeholder control and then I create a label and add the label to the placeholder
[Code]....
On the first page load when navigating to the page, the grid dispays perfectly and the labels are created with no issues and I can see the "1" in every single cell of the Gridview. I basically need the labels in the cells to store an ID when the cell is clicked (the click event works with no issues, wired it all up with javascript) and Since the Cells to not exist prior to "Building the matrix" method, How can I persist the Label controls inside of the tablecells between postbacks so I can assign and read values from them.
I've read a number of online posts from 4guys from rolla and they demonstrate how to persist a handful of controls dynamically created in a staticly defined PlaceHolder conrol outside of the complicated setup of the gridview and have failed at adapting them. The golden rule seems to be to 'recreate' the controls during Page_PreInit during the postback, but I can't seem to get it working.
.I am new to asp.net.Is there any way we can limi the width of the gridview in the design mode.
I have to put 15-20 columns on the gridview.When I add columns to gridview the width shoots out of the page and the page design is seems ruined.
i placed it inside the panel and added scrol bars to it. it looks ok when debuggin i.e looks ok in internet explorer but in design mode it ruins the page design.
I have created an ASP page to display records for auditor review and response. The page consists of two repeaters that display 5 rows from a database at a time. for each row displayed, a RadioButtonList, containing two buttons is attached. If the second button is selected, an input text box is displayed to allow auditor comments.
My situation is that I cannot find a way to identify which row is being selected? When I select the Button that should enable the text box, I'm receiving the following error:
"Object reference not set to an instance of an object"
I'm just starting out in ASP coding and would like to know what I'm not doing right?
can you please help me to brainstorm the possible causes of this error. I've got a paged repeater with localisation bound programitcally to an sqldatasource using a stored proc. I can post code if needs be but it's rather long. I'm looking for typical causes of this error + will make note for future reference!
erver Error in '/WebSite4' Application.
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
[Code]....
Line 233:Line 234: Repeater1.DataSource = PagedResultsLine 235: Repeater1.DataBind()Line 236: doPaging()Line 237: End Sub
Again, I am new to the ASP.NET world, and I come from a Windows Forms background. I'm working with an ObjectDataSource that retrieves a collection of business objects. With the collection, I am going to be binding it to a CheckBoxList and other various controls. The business object that I am using is an Employee.
To get all of the employees, I create an ObjectDataSource and set the "Select" method. I then set the DataSourceID of the CheckBoxList to be that of the ObjectDataSource. When I load the page for the first time, I see all of the employees. Now, the user goes through this page and selects all the employees they want to see information about (by checking the box next to the employee name). Finally, the user hits the button called "Display." Upon postback how do I get a list of those employees? I've tried the following solution, but I'm not sure if it's the best practice in obtaining all those employees again. Here's my solution...
In the CheckBoxList, I set the DataTextField to the Employee's name. I also set the CheckBoxList's DataValueField. This property is a little different. I set this to be a UNIQUE IDENTIFIER, which can distinguish this employee from other employees. Now, when the user hits the button "Display" I use my ObjectDataSource again and MANUALLY call ObjectDataSource.Select(). I cast the returned value as a List<Employee>. Finally, I iterate through all list items in the CheckBoxList...
[Code]....
If the item is selected, I parse through my list of employees that was returned from the bjectDataSource.Select(). I use the item.Value and compare it to each employee's "key." If the key is found, I know that the employee is selected. I put this employee in another list called EmployeesSelected.
Finally, I take EmployeesSelected (which is a List) and set my GridView's .DataSource and call .DataBind() on the GridView.
Is this the "best practice" of re-obtaining the Employees that are selected on my page, or am I making this too complicated?
My problem is I get an "Object reference not set to an instance of an object." error at runtime on the line "ddl2.SelectedValue = cat1". Ironically I got this from an example on the internet and the only difference is my Cat1 varible which has the correct value at runtime.
I would like to enable/disable the field BagNo in my gridview, depending on the value of another field in the gridview called ScriptNo, when I click the edit button I get this message "Object reference not set to an instance of an object".
here is the code
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing Dim row As GridViewRow = GridView1.Rows(e.NewEditIndex) If DirectCast(row.FindControl("ScriptType"), TextBox).Text = "TTA" Then
I have a tablecell where I import the text from a SQL database and this all works well, except that the carriage returns are not being displayed in the text.
I have done some googling and although I do not get any error messages, the carriage returns are not appearing in my table cell.
Here is the code:
[Code]....
I have also tried Environment.NewLine, etc. but all to no avail.
Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound ' display placeholder image if no imageId Dim ltrImage1 As Literal = CType(e.Item.FindControl("Image1"), Literal) Dim ltrImage2 As Literal = CType(e.Item.FindControl("Image2"), Literal) Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView) If String.IsNullOrEmpty(drv("ImageId").ToString) Then ltrImage1.Text = "<img src=""images/properties/x_thumb.gif"" alt="""" />" ltrImage2.Visible = False End If End Sub