Hello all, <BR><BR>With some help from posters here I've managed to build the following datagrid, but I've run into several problems (listed below) when attempting to use the grid for my purposes. This is quite long, I appologize: <BR><BR>http://216.87.15.155/datagrid.gif<BR><BR>What I'm attempting to do is the following: <BR><BR>1. create a dataGrid with databound pulldowns from several different SQL tables, then select (or put at the top) a predefined default for each dropdown.<BR><BR>I've accomplished this task the following way:<BR><BR>a) created the dataGrid and added several template columns like this one ...<BR><BR><asp:TemplateColumn HeaderText="Font Color"> <BR><ItemTemplate><BR><asp
ropDownList id="lstFontCols" runat="server" DataSource='<%# getFontCols(DataBinder.Eval(Container.DataItem, "styleClassID"))%>' DataTextField="fontColorName" DataValueField="styleFontColorID" onSelectedIndexChange='<%# changeExample(Container.ItemIndex)%>' AutoPostBack="True" /><BR></ItemTemplate><BR></asp:TemplateColumn><BR><BR>b) As the datagrid is being built each dropdown is calling its own datasource function e.g., getFontCols (going to use font colors for these examples). Here is the getFontCols function ...<BR><BR><BR>protected function getFontCols(styleClassID AS integer)<BR> dim fFamComm AS new SqlDataAdapter("SELECT fc.styleFontColorID,fc.fontColorName FROM wsStyleFontColors fc LEFT JOIN wsStyleClasses c ON fc.styleFontColorID=c.styleFontColorID AND c.styleClassID=@styleClassID ORDER BY c.styleFontColorID DESC,fontColorName", objConn)<BR> fFamComm.SelectCommand.Parameters.Add(new sqlParameter("@styleClassID", sqlDbType.int))<BR> fFamComm.SelectCommand.Parameters("@styleClassID").Value = http://aspmessageboard.com/archive/index.php/styleClassID <BR> dim ds AS new DataSet()<BR> fFamComm.Fill(ds, "fontCols")<BR> return ds.Tables("fontCols")<BR>end function <BR><BR><BR>Which results in the desired outcome.<BR><BR><BR>Problems I'm having: The onSelectedIndexChange event is firing on page load because it's changing from -1 when binding the data to the dropdown. This ends up executing my changeExample function, which I don't want to do yet. I know I could fix this with an if NOT isPostBack, but that seems rather bootleg. <BR><BR><BR><BR>2. When the user chooses anything from any of the pulldowns the page changes the "Style Example" text to reflect their selection. <BR><BR>I'm attempting to do this using AutoPostBack and executing the following function onSelectedIndexChange<BR><BR><BR>protected function changeExample(curItem AS integer)<BR><BR>dim I AS integer<BR>dim styleExample AS label<BR>dim curStyle AS new StringBuilder()<BR>dim lstFontCols AS DropDownList<BR>dim lstFontFams AS DropDownList<BR>dim lstFontSizes AS DropDownList<BR>dim lstFontWeights AS DropDownList<BR><BR>For i=0 To styleClassGrid.Items.Count - 1<BR><BR> styleExample = styleClassGrid.Items(i).FindControl("styleExample")<BR> lstFontCols = styleClassGrid.Items(i).FindControl("lstFontCols")<BR> lstFontFams = styleClassGrid.Items(i).FindControl("lstFontFams")<BR> lstFontSizes = styleClassGrid.Items(i).FindControl("lstFontSizes")<BR> lstFontWeights = styleClassGrid.Items(i).FindControl("lstFontWeights")<BR> <BR> curStyle.Append("color:" & lstFontCols.SelectedItem.text &"; ") <BR> curStyle.Append("font-family:" & lstFontFams.SelectedItem.text &"; ")<BR> curStyle.Append("font-size:" & lstFontSizes.SelectedItem.text &"; ")<BR> curStyle.Append("font-weight:" & lstFontWeights.SelectedItem.text &"; ")<BR> <BR> Message.InnerHtml &= curStyle.toString() & "<BR><BR>"<BR> styleExample.style = curStyle.toString()<BR><BR>Next<BR> <BR>end function<BR><BR><BR>Problems I'm having: The first issue I have is that the For loop is running way too many times. When the page loads it's triggering the onSelectedIndexChange, which runs this function. The For loop is then iterating through all items as the datagrid is being built, which results in an exponential increase in the number of times it runs. I'd love to do away with the for loop all together (it's not necessary since I'm passing the row number to the function), but if I remove it, I repeatedly get an out of index error. <BR><BR>The second issue is that the function is grabbing the default text value from each pulldown rather than the value the user selected. It seems this is because each dropdown menu is being rebuilt on page load, but the pulldowns are managing to retain the item the user selects. <BR><BR>The final obstacle I've encountered is being able to dynamically change the label style to something like this: <BR><BR>style="color:Black; font-family:Arial; font-size:10 pt; font-weight:Normal;" <BR><BR>Using lableName.style = "" doesn't work because it's an inherited attribute, so any help with something like this would be nice as well. <BR><BR><BR>That's all, if you made it this far I applaud you! I've read through an insane number of articles, but nothing I've found has addressed these specific issues. <BR><BR>Thanks for any help anybody may be able to provide. <BR><BR>])ryI think this is what you need for problem 2. I'm not positive though. When your page is first loaded all the listBox.SelectedIndex values are -1 but once the page is submitted then change to 0. What you need to do it set the selectedItem = 0 when the list is built. Not sure if that is any help at all.<BR>for those of you that read through this novel, I've managed to solve all problems. For the styles I'm dynamically creating style classes and then reassigning the label.cssClass attribute on page load. Everything else was solved with a combination of viewstate, dataset caching and interesting if NOT isPostBacks. <BR><BR>Cheers,<BR><BR>])ry
