FineUI 官方论坛

标题: GRID中使用ASP的DropDownList控件,OnSelectedIndexChanged只对第一行起 [打印本页]

作者: 大鸟打小鸟    时间: 2012-12-29 09:23
标题: GRID中使用ASP的DropDownList控件,OnSelectedIndexChanged只对第一行起
三石大人您好!我在GRID中使用了ASP的DropDownList控件,但是在使用中OnSelectedIndexChanged只对第一行起作用!这是什么原因呢?

  1. <form id="form1" runat="server">
  2. <ext:PageManager ID="PageManager1" runat="server" AjaxAspnetControls="aspDdl,aspTb" />
  3. <ext:Grid ID="gridTest" ShowBorder="true" ShowHeader="true" EnableCheckBoxSelect="True" ForceFitAllTime="True"
  4. Title="明细" EnableMultiSelect="True" EnableRowNumber="True" runat="server" OnRowDataBound="gridTest_RowDataBound">
  5. <Columns>
  6. <ext:TemplateField HeaderText="选择" Width="100px">
  7. <ItemTemplate>
  8. <asp:DropDownList runat="server" ID="aspDdl" Width="80%" OnSelectedIndexChanged="aspDdl_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
  9. </ItemTemplate>
  10. </ext:TemplateField>

  11. <ext:TemplateField HeaderText="文本" Width="100px" >
  12. <ItemTemplate>
  13. <asp:TextBox ID="aspTb" runat="server" Width="80%" TabIndex='<%# Container.DataItemIndex + 10 %>'
  14. Text='<%# Eval("Description") %>'></asp:TextBox>
  15. </ItemTemplate>
  16. </ext:TemplateField>

  17. </Columns>
  18. </ext:Grid>



  19. </form>
复制代码
  1. public partial class WebForm1 : System.Web.UI.Page
  2. {
  3. protected void Page_Load(object sender, EventArgs e)
  4. {
  5. if (IsPostBack)
  6. return;

  7. gridTest.DataSource = GetDdlBind();
  8. gridTest.DataBind();
  9. }

  10. protected void gridTest_RowDataBound(object sender, FineUI.GridRowEventArgs e)
  11. {
  12. GridRow row = gridTest.Rows[e.RowIndex];

  13. var aspDdlCompany = (AspNet.DropDownList)row.FindControl("aspDdl");
  14. aspDdlCompany.DataSource = GetDdlBind();
  15. aspDdlCompany.DataTextField = "Product";
  16. aspDdlCompany.DataValueField = "Version";
  17. aspDdlCompany.DataBind();

  18. }

  19. protected void aspDdl_SelectedIndexChanged(object sender, EventArgs e)
  20. {
  21. GridRow row = gridTest.Rows[gridTest.SelectedRowIndex];
  22. var aspDdl = (AspNet.DropDownList)row.FindControl("aspDdl");
  23. var aspTb = (AspNet.TextBox)row.FindControl("aspTb");

  24. aspTb.Text = aspDdl.SelectedValue;
  25. }


  26. private DataTable GetDdlBind()
  27. {
  28. DataTable tblDatas = new DataTable("Datas");
  29. DataColumn dc = null;
  30. dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
  31. dc.AutoIncrement = true;//自动增加
  32. dc.AutoIncrementSeed = 1;//起始为1
  33. dc.AutoIncrementStep = 1;//步长为1
  34. dc.AllowDBNull = false;//

  35. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
  36. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
  37. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));

  38. DataRow newRow;
  39. newRow = tblDatas.NewRow();
  40. newRow["Product"] = "大话西游";
  41. newRow["Version"] = "2.0";
  42. newRow["Description"] = "我很喜欢";
  43. tblDatas.Rows.Add(newRow);

  44. newRow = tblDatas.NewRow();
  45. newRow["Product"] = "梦幻西游";
  46. newRow["Version"] = "3.0";
  47. newRow["Description"] = "比大话更幼稚";
  48. tblDatas.Rows.Add(newRow);
  49. return tblDatas;
  50. }
  51. }
复制代码
[attach]1528[/attach]
[attach]1529[/attach]
作者: sanshi    时间: 2012-12-31 21:02
测试了一下,两行中的下拉列表都能触发,只不过在更新模板列之后,要手工调用 UpdateTemplateFields:
  1. protected void aspDdl_SelectedIndexChanged(object sender, EventArgs e)
  2.         {
  3.             GridRow row = gridTest.Rows[gridTest.SelectedRowIndex];
  4.             var aspDdl = (AspNet.DropDownList)row.FindControl("aspDdl");
  5.             var aspTb = (AspNet.TextBox)row.FindControl("aspTb");

  6.             aspTb.Text = aspDdl.SelectedValue;

  7.             gridTest.UpdateTemplateFields();
  8.         }
复制代码


[attach]1534[/attach]
作者: 大鸟打小鸟    时间: 2013-1-2 13:16
原来如此,谢谢三石了{:soso_e100:}




欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/) Powered by Discuz! X3.4