Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2006, 05:15 PM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to cmedllo@tams.com
Default selectedvalue dynamic edititemtemplate ascx

I have a dropdownlist in a usercontrol.
I dynamically load the control in a datagrid.
the itemtemplate is just a label of value from dataset for the datagrid
clicking on edit does display the ascx control dropdown with all the values

from the binddata method inside ascx. In the aspx file I can get the value I

am looking for from the datagrid underlying dataset but how and when am I

getting this to the ascx control?

//aspx file

TemplateColumn tcl5 = new TemplateColumn();
ITemplate temp= Page.LoadTemplate("Controls/StoreSelector.ascx");
tcl5.EditItemTemplate = temp;
dgRt2.Columns.Add(tcl5);


private void dgRt2_ItemDataBound(object sender, DataGridItemEventArgs e)
{
    DataGrid dg = (DataGrid)sender;
    int cnt = e.Item.ItemIndex + (dg.PageSize * dg.CurrentPageIndex);
    DataTable dtBound = (DataTable)dg.DataSource;

//from the dt get the value I want to select
    string strZone = dtBound.Rows[cnt]["zonelu"].ToString();
//I try to cast the dropdown in the grid so I can set the selected value
    SISWebAdmin.Controls.StoreSelector ddlz =

(SISWebAdmin.Controls.StoreSelector)e.Item.Cells[0].FindControl("storeList");
                ddlz.SelectedValue = strZone;

//ascx file
// I have a public property SelectedValue
public string SelectedValue
{
    get{return storeList.SelectedValue;}
    set{storeList.SelectedValue = value;}
}

// problem maybe that in the ascx file in page load I cannot check for post

back because the list is only loaded on the postback but the error I get is

e1 at SISWebAdmin.WebForm1.dgRt2_ItemDataBound(Object sender,

DataGridItemEventArgs e) in c:\program files\common files\microsoft shared\web

server extensions\60\template\layouts\siswebadmin\webform 1.aspx.cs:line 804 at

System.Web.UI.WebControls.DataGrid.OnItemDataBound (DataGridItemEventArgs e) at

System.Web.UI.WebControls.DataGrid.CreateItem(Int3 2 itemIndex, Int32

dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,

DataGridColumn[] columns, TableRowCollection rows, PagedDataSource

pagedDataSource) at

System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean

useDataSource) at

System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e) at

System.Web.UI.WebControls.BaseDataList.DataBind() at

SISWebAdmin.WebForm1.fillgrid(String sFullname, String strZone, String strArea,

String strTitle) in c:\program files\common files\microsoft shared\web server

extensions\60\template\layouts\siswebadmin\webform 1.aspx.cs:line 368Object

reference not set to an instance of an object.SISWebAdmin






Similar Threads
Thread Thread Starter Forum Replies Last Post
Get SelectedValue of Control obrienkev C# 2005 3 November 8th, 2007 12:17 PM
Need Help with DropDownList SelectedValue putputty ASP.NET 2.0 Basics 4 June 27th, 2007 11:44 AM
Datalist-edititemtemplate-RadioButtonList cp75 ASP.NET 1.0 and 1.1 Basics 1 September 1st, 2006 12:56 PM
comboBox.SelectedValue melvik C# 1 August 19th, 2003 09:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.