DropDown list in grid for editing data directly

May 30, 2011 at 1:35 PM

hi, 

At first, Good library of controls.

 

I'd like to know how can i triggered the event fired from a drop down list in a grid.

i built something like that:

 <ext:Grid ID="gridUsers" runat="server" EnableCheckBoxSelect="false" EnableRowNumber="true"
                CssStyle="position:relative; float:left" EnableAlternateRowColor="true" EnableMouseOverColor="true"
                Title="Utenti" AllowPaging="true" AllowSorting="false" Width="1024px" AutoHeight="true"
                AutoWidth="true" DataKeyNames="UserId" OnSort="gridAccounts_Sort" EnableMultiSelect="false"
                OnPageIndexChange="gridUsers_PageIndexChange" OnRowDataBound="gridUsers_RowDataBound">
                <Columns>
                    <ext:TemplateField ColumnID="cmbActionCol" HeaderText="Action" Width="200px">
                        <ItemTemplate>
                            <asp:DropDownList ID="cmbAction" runat="server" AutoPostBack="true" Width="180px"
                                OnSelectedIndexChanged="cmbAction_SelectedIndexChanged" DataSource='<%# GetCmbData( DataBinder.Eval(Container.DataItem, "UserId").ToString())%>'>
                            </asp:DropDownList>
                        </ItemTemplate>
                    </ext:TemplateField>                   
                    <ext:TemplateField HeaderText="UserId" ColumnID="UserId" SortField="UserId">
                        <ItemTemplate>
                            <b>
                                <%# DataBinder.Eval(Container.DataItem, "UserId")%></b>
                        </ItemTemplate>
                    </ext:TemplateField>
                </Columns>
            </ext:Grid>
        
	protected void cmbAction_SelectedIndexChanged(object sender, EventArgs e)
      {
          //btnSaveContinue_Click(sender, e);
      }

      protected void gridUsers_RowDataBound(object sender, GridRowEventArgs e)
      {
          var account = e.DataItem as UserEntity;
          if (account != null)
          {
              var res = new List<System.Web.UI.WebControls.ListItem>();
              res = GetAction();
              cmbAzioniConcesse.DataSource = res;
              cmbAzioniConcesse.DataBind();

              cmbAzioniConcesse.SelectedIndexChanged += new EventHandler(cmbAction_SelectedIndexChanged);
          }
      }
	  
      protected List<System.Web.UI.WebControls.ListItem> GetCmbData(string userId)
      {
		  var account = h.SearchByUsername(userId).FirstOrDefault();
          if (account != null)
          {
              var res = new List<System.Web.UI.WebControls.ListItem>();
              return GetAction();
          }

          var listItem = new List<System.Web.UI.WebControls.ListItem>();
          listItem.Add(new System.Web.UI.WebControls.ListItem
          {
              Text = "<-- Select -->",
              Value = "0",
          });

          return listItem;
      }

how can i handled whit postback the selecionIndexChanged event?

Thanks

 

Nikko_

Jun 14, 2011 at 5:58 AM

                <Columns>
                     <ext:TemplateField ColumnID="cmbActionCol" HeaderText="Action" Width="200px">
                        <ItemTemplate>
                        <asp:DropDownList Hidden="false" ID="cmbAction" runat="server" AutoPostBack="true" Width="180px" OnSelectedIndexChanged="test">
                            <asp:ListItem Text="111" Value="111" />
                            <asp:ListItem Text="222" Value="222" />
                        </asp:DropDownList>
                        </ItemTemplate>
                    </ext:TemplateField>    
               </Columns>

my testing environment is: ExtAspNet 2.3.2, IE 7 and Firefox 4.

i narrow down your interesting idea and focus on the codes above.

the event OnSelectedIndexChanged can not be fired as you said.

and i found other two problems:

1. in IE 7, the ddl can be rendered, while in Firefox 4, it can not be seen.

2. the ddl could be dropped down for further selection only if the corresponding line in the grid got focus in advance.

hence, even if you can solve your problem and fire the event OnSelectedIndexChanged, problem 2 i mentioned will make the feature less elegant and attractive.