Forms Data Controls :: Setting Properties On Web User Control In Dynamic GridView

Jan 7, 2010

I am in need of some assistance in regards to how to best set the values of properties for a Web User Control which is being included into a cell of a GridView with dynamically created columns. I have tried a few different approaches, but can't seem to get a satisfactory result. Also, to be completely honest, I am not really sure if I am using best practices for what I am trying to accomplish.

First off a little background:I have a GridView for which we will never know the exact number of columns at run time. The columns are predicated by user selection. I am creating the command text for the DataSet on the fly and then looping through the columns of the resulting DataTable in order to use custom TemplateFields. This works ok for just printing out the row values but not so much for when I need to insert the Web User Control into a cell.The Web User Control is in essence a collection of image links which are used as a "Quick Nav" tool. I need to pass the values of 2 fields from each DataRow to the control via properties (for example, CustID and ProductID). I am using custom TemplateField classes inheriting from ITemplate for displaying my fields and extending the DataBinding event like so: [Code]....

This won't work for my User Control as DataBinding is called after the control is loaded into the page and I need the properties to be set before the Page_Load event of the control is fired.Is there a GridView event I should be looking into instead such as RowCreated or RowDataBound? Or should I modify how I loop through the DataTable by doing rows first, then the resulting columns as I've seen done elsewhere?

View 5 Replies


Similar Messages:

Web Forms :: Dynamic User Control And Setting Properties?

Jan 25, 2011

I have a user control (i.e. ascx) that comprises of two related list boxes (i.e. once you change the selected item in one list the contents of the other list update). I'm adding this user control dynamically to a page on the click event of a button (i.e. using LoadControl).I wish to set the list box datasource properties, as well as the default selected item of the parent list from my parent page so I created public properties in my user control to accomodate this. I also created an event in my user control that notifes the parent page when the selected item changes in one of the list boxes so I can update the contents of the other list box.

I understand that I have to recreate the user control on every postback in order for it to function correctly but I'm not sure exactly how I should be doing it. I've shown below what I have currently - whilst it works the problem is that on postback I'm always creating the user control with all its default properties and then updating the properties that need to change(?). For example, when the choice in theparent list box changes the datasource of the list box is set twice (once in AddControl and then again in OnParentChanged)? As the contents of the list boxes originate in a database it means I'm making unnecessary calls to the database (unless I do some something like store each unique set of data in the ViewState).

I'd be very grateful if someone could review how I've done things and illustrate how perhaps I should be doing things. I'm not sure if the way I've done this is considered the 'correct' way. For example there may be a better way of doing things would avoid setting the properties twice? I'm a bit unsure of the way I've set the datasource properties of the list boxes and bound them. I wished to set the datasource from the parent page because I might have a second user control on my page that may also use the same datasource and I could reuse it (as opposed to each control making its own call to the database) so I'd like to keep this feature if possible.It would be great if posting code in reply that you use my example as a guide so I know what you're referring to.Here's the code for my user control:

[Code]....

[Code]....

Here's the code for my containing page:

[Code]....

View 1 Replies

Forms Data Controls :: Dynamic Link Buttons In External Gridview Pager User Control Don't Fire Command

Nov 16, 2010

I'm customizing a NopCommerce store, and am using a gridview to display and sort the products. All that works well. I like how the external pager (user control) works with the gridview, with one exception -- it uses the hyperlink control, so I lost viewstate, which I need to retain for both the search page and to retain the gridview sort options. Based on the page selected (from the pager control), I query the database and rebind the gridview. So, I switched the user control to use LinkButtons instead of Hyperlinks. This is the sample code for one of the buttons:

[Code]....

I set a breakpoint inside the lbCommandClick method, but it never gets hit. Reading other posts tells me that I would have to add the dynamic controls in the OnLoad method, but since this all happens based on other data on the page (say search results), I don't think I can do it onLoad. However, the link buttons do work to cause a postback, and my viewstate is saved correctly. The only problem is that I do not know which button was clicked. I could check Request.Params["__EVENTTARGET"] onLoad, but that is kind of a hack -- I'd much rather be able to set the event handler in the user control and use the CommandArgument property. But, what I have tried so far fails.

Especially one that would allow me to set the EventHandler in the User Control? (e.g. OnlbCommand="PagerLBPageChange" )

View 3 Replies

Forms Data Controls :: GridView Dynamic Column - Setting DataFormatString Not Working?

Oct 20, 2010

I am dynamically creating columns for my GridView and the DataFormatString is not doing anything.

Code snippet

[Code]....

View 3 Replies

Forms Data Controls :: Setting Properties From A Database?

Oct 4, 2010

I have a database which holds the path of an image. It also holds the recomended height and width of the image. My question is how can I set the height and width properties from my database? I have tried the following with no avail:

[Code]....

View 6 Replies

Forms Data Controls :: Setting Bound Field Properties?

Mar 11, 2011

eI am using themes to set the Gridview font size and font name. I need to set the boundfield to the same font and size as I want it to be application to all the columns in gridview. How can I specify the boundfield properties in the themes.

View 8 Replies

Web Forms :: Finding Control Id And Setting Properties In Other Pages?

Oct 23, 2010

im using a webusercontrol (hide.ascx) it has 2 buttons btn_hide,btn_expand

and in my other forms of all like(products.aspx)customers.aspx,orders.aspx

im using a panel conrol(pnl_products) where in im placing all the input controls.

i want to find the panel control in hide.ascx page and to set that

panel.visble=true/false property in this page.

View 2 Replies

Web Forms :: Setting Properties On A Dynamically Loaded Control As Template?

Jan 6, 2010

[Code]....

Once the template is loaded and cast back to the TabHeader class, it's null. How can I load that control, set the properties, and use it as the template? Or is the only way to go about doing this to create a custom class?

View 2 Replies

Forms Data Controls :: Dynamic User Control With A Grid View?

Dec 13, 2010

I am dynamically loading user controls into my main page on button event.The user control has a textbox and a gridview When i enter data in textbox , the autopostback event fires and loads data into the gridview. when i load another instance of user control and do any post back the gridview data is not persisting.Until and unless I bind the data, gridview is not having any data after postback.This is creating issue when I al updating a row in gridview as data is not persisting after postback.

View 8 Replies

Forms Data Controls :: Setting Focus To A Control In Gridview Edit Mode?

May 1, 2010

I have a gridview with edit functionality and using the EditItemTemplate section. I am trying to set focus to a textbox when user selects the edit mode.

[Code].....

View 6 Replies

C# - Setting Custom Control Properties?

Apr 20, 2010

I though it would be very simple but I can not get it today.I have a user control, with a grid control contained in it.

public Unit Width
{
get

[code]...

View 1 Replies

DataBind Versus Setting Control Properties

Nov 9, 2010

Regarding these two approaches:

<asp:Label ID="Label1" runat="server"><%# DateTime.Now %></asp:Label>

and

Label1.Text = DateTime.Now.ToString();

Which do you use and why?

View 2 Replies

Forms Data Controls :: Finding The Dynamic Templatefield Control In A Gridview?

Dec 16, 2010

I have a gridview where I in codebehind add a templatefield

[Code]....

In my update command when i try to find the "Result" textbox I get a null object
[Code]....

In the gridview there is another templatefield "Name" that consist of two boundfields("Firstname" and "Lastname") This column is added in the design phase and not in the codebehind.I don't have any trouble finding these controls using the ID added in the markup
[Code]....My issue is with the result column that I add in codebehind.

View 3 Replies

Forms Data Controls :: C# Dynamic Gridview Using Template Field As Control?

Mar 31, 2010

I have a gridview and basically at page load I want it to display with an empty row. The first field in the gridview would be a template field containing a textbox. I wan't to be able to type in, for example, a product code ('abc'). This would be the parameter for the stored procedure and then the rest of the columns (40+ additional columns) in the gridview would populate with the rest of the data pertaining to that product code (i.e. price, unit of measure, etc.). In short the template field texbox is the control to bind the gridview.

After the row is populated I could click a button or link that would add that entire row to my gridview and then add another empty row where I could enter another product code... populate the row then add that row to the gridview. and so on...

View 5 Replies

Forms Data Controls :: Gridview Dynamic LinkButton Control With CommandName ?

Jun 13, 2010

the structure is like this:

Grivdivew
ItemTemplate
PlaceHolder
/ItemTemplate
/Gridview

And then I try to add some dynamic controls into the placehold control from code behind, I use the RowDataBound Event

Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim ph As PlaceHolder = CType(e.Row.Cells(1).FindControl("PlaceHolder"), PlaceHolder)[code]....

The problem is the button CommandName is not functioning. And more strangely, if I add the button manually into the placeholder, like this:
Grivdivew
ItemTemplate
PlaceHolder[code]....

View 5 Replies

Web Forms :: Access User Control Properties In Another User Control

Nov 9, 2010

I want to use a couple of instances of the same control on a page. The user control is intended to display a list of records in a repeater. The aim is that the second control will show a list excluding the IDs in the first control The control has a number of public properties, including IDsInThisList, and IDstoExclude. The query will exclude the IDs in the second property.

What I would like to do is get the record IDs from the first instance of the control (IDsInThisList), and pass them to the second contro as the IDsToExclude.

I have a test page where I am setting the properties of the controls in code. As you might guess, it's not working! The first control displays the top 3 items, as desired, but the second display the records 1-7, rather than records 4-10 because it is not receiving the IDstoExclude from the first control When I response write the IDstoExclude from the first control in my testpage, the string is empty. (if I do it from within the control, it shows the IDs)

How can I get the controls to fire in order and pass values to each other?

Screen grab of test page + uc and test page code attached

[Code]....

View 5 Replies

Forms Data Controls :: Create And Persist A Dynamic Control Inside Of Each Gridview TableCell

Jan 25, 2011

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.

View 1 Replies

Forms Data Controls :: Using GridView With A User Control And Passing Object Into Control?

Jan 8, 2010

I would like to use the gridview paging feature and have built a gridview with a user control. The data source has lots of columns, so to make it easier I want to return a LIST<MyObject> and just pass <Myobject> into the user control rather than all the data elements. Not sure how I access the object of the data source to bind to the control. Assume it would be during ondatarowbound.

Also, my guess is there is a better way to do this than gridview. I'd take either solution that allows me to have easy paging and pass the complete object into the user control

View 7 Replies

Forms Data Controls :: Dynamic Gridview Inside A Dynamic Gridview?

Oct 9, 2010

If there's a better way to accomplish what I'm attempting I haven't found it yet. That being said, I have create a gridview like the one here,[URL]And with some minor tweaking it working great for all my fields, checkboxes, etc. The issue is my last column is another gridview, and I'd like it to function the same. that is, a dynamic gridview inside of a dynamic gridview. I get that I have to create it initially with null values or it won't show up. I guess what I'm having trouble figuring out is instead of go will null data in the parent gridviews column, do I place my blank child gridview. Do I create and bind the child gridview first, or second. Generally just not sure. Also, as far as storing the data from the child gridview goes, will each one need it's own datatable?

[Code]....

[Code]....

View 5 Replies

Custom Server Controls :: Composite User Web Control - Properties - Best Practice

Jan 12, 2011

I would like to ask you what is the best practice for developing composite user web control with multiple controls inside from the stand point of dealing with properieties. In my situation I would like to use header menu bar with logos, buttons, java baset visible/hidden menus itc as web control. I was successfull in implementing new control in my project.

But my question goes to issue of properties for ALL OF controls. I know how to hard code all required properties like: text, visible, enable for all controls. It's a lot of work. ( This is the very edge of my asp.net comprehension ) Is there a more elegant way provide an access to controls's properties without hard coding seperatelly?

View 12 Replies

Forms Data Controls :: Access A Control Inside A Repeater Control And Change Its Properties?

Nov 26, 2010

I need to access a control inside a repeater and change its properties. To enable it or not. I got an erorr message Object reference not set to an instance of an object. Here is my code inside a method. protected void

rptCAP_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
LinkButton lnDel = (LinkButton)rptCap.FindControl("lnkDelete");
lnkDel.Enabled = false; //<<<<< this is where the error occur
}

The name of the repeater control is id="rptCAP"

View 3 Replies

AJAX :: Dynamic Loading Web User Control With Gridview Updatepanel?

Jan 8, 2010

Wasn't quite sure where to post this, seems like the issues could be any number of things, so I'm trying to keep it general... mods, feel free to relocate appropriately.

I am trying to build a page which will load various web user controls dynamically in response to menu selections made by the user, and then allow other interactions inside those controls (such as gridview manipulation and updates). The content page simply has a loginview, an ASP:Menu control, and an ASP:Placeholder. The placeholder is filled by the appropriate user control in response to the menu selection. Selecting a menu item causes a postback and the correct control is loaded as expected.

I realized that using dynamic loading with interactive controls would be a problem with respect to postbacks, so I added a ScriptManager to the content page and enclosed the gridview controls in the web user controls within UpdatePanels, thinking that all postbacks required by the GridView would be handled inside the UpdatePanel and not cause the parent page to refresh (which would then wipe out the dynamically loaded control). However, it does not seem to work this way. Instead, although the control containing the GridView loads correctly and displays data, when I attempt to page, edit, or select any item on the GridView, nothing happens on the first click. If I click on any item inside the control a second time, the entire page refreshes and the control and its contents disappear.

I have removed all the code inside the web user control and placed it directly into the content page to test, and everything functions correctly in that case. I think therefore that I must be missing something with how the user control is working, particularly with respect to the UpdatePanel. Is it just not possible to use an UpdatePanel to confine actions inside a user control that would otherwise cause the entire page to postback, or am I missing something somewhere?

Psuedo-code for the issue below

Content page

[Code]....

Control

[Code]....

View 1 Replies

Forms Data Controls :: Gridview Inside User Control Databind/how To Set The Datasoruce Property Of Gridview

May 8, 2010

I am developing a usercontrol which has a gridview control in it.

Now I want to set the datasoruce property of gridview. Datasoruce will be a generic list (List<Class>).

How to do this ?

View 1 Replies

Web Forms :: Want To Set/get Some Values For Currently User Control Properties?

May 15, 2010

i have a multiple user controls, each user control has multiple properties, i am loading those controls dynamically in my aspx page,i save the user control name in a hidden field in my aspx page,so i can know whats usercontrol are currently loaded,now i want to set/get some values for Currently user control properties,how can i know the properies available for that dynamics loads control ?also how to know the class for that control ?

View 3 Replies

Web Forms :: Access To User Control's Properties?

Mar 11, 2011

How to access userControl's properties, when use FindControl method?

View 7 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved