set selectedvalue in dynamic edititemtemplate for ascx dropdown in

Joined
Sep 20, 2006
Messages
1
Reaction score
0
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\webform1.aspx.cs:line 804 at

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

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

dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,

DataGridColumn[] columns, TableRowCollection rows, PagedDataSource

pagedDataSource) at

System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean

useDataSource) at

System.Web.UI.WebControls.BaseDataList.OnDataBinding(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\webform1.aspx.cs:line 368Object

reference not set to an instance of an object.SISWebAdmin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top