三石大人您好!我在GRID中使用了ASP的DropDownList控件,但是在使用中OnSelectedIndexChanged只对第一行起作用!这是什么原因呢?
- <form id="form1" runat="server">
- <ext:PageManager ID="PageManager1" runat="server" AjaxAspnetControls="aspDdl,aspTb" />
- <ext:Grid ID="gridTest" ShowBorder="true" ShowHeader="true" EnableCheckBoxSelect="True" ForceFitAllTime="True"
- Title="明细" EnableMultiSelect="True" EnableRowNumber="True" runat="server" OnRowDataBound="gridTest_RowDataBound">
- <Columns>
- <ext:TemplateField HeaderText="选择" Width="100px">
- <ItemTemplate>
- <asp:DropDownList runat="server" ID="aspDdl" Width="80%" OnSelectedIndexChanged="aspDdl_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
- </ItemTemplate>
- </ext:TemplateField>
- <ext:TemplateField HeaderText="文本" Width="100px" >
- <ItemTemplate>
- <asp:TextBox ID="aspTb" runat="server" Width="80%" TabIndex='<%# Container.DataItemIndex + 10 %>'
- Text='<%# Eval("Description") %>'></asp:TextBox>
- </ItemTemplate>
- </ext:TemplateField>
- </Columns>
- </ext:Grid>
- </form>
复制代码- public partial class WebForm1 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (IsPostBack)
- return;
- gridTest.DataSource = GetDdlBind();
- gridTest.DataBind();
- }
- protected void gridTest_RowDataBound(object sender, FineUI.GridRowEventArgs e)
- {
- GridRow row = gridTest.Rows[e.RowIndex];
- var aspDdlCompany = (AspNet.DropDownList)row.FindControl("aspDdl");
- aspDdlCompany.DataSource = GetDdlBind();
- aspDdlCompany.DataTextField = "Product";
- aspDdlCompany.DataValueField = "Version";
- aspDdlCompany.DataBind();
- }
- protected void aspDdl_SelectedIndexChanged(object sender, EventArgs e)
- {
- GridRow row = gridTest.Rows[gridTest.SelectedRowIndex];
- var aspDdl = (AspNet.DropDownList)row.FindControl("aspDdl");
- var aspTb = (AspNet.TextBox)row.FindControl("aspTb");
- aspTb.Text = aspDdl.SelectedValue;
- }
- private DataTable GetDdlBind()
- {
- DataTable tblDatas = new DataTable("Datas");
- DataColumn dc = null;
- dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
- dc.AutoIncrement = true;//自动增加
- dc.AutoIncrementSeed = 1;//起始为1
- dc.AutoIncrementStep = 1;//步长为1
- dc.AllowDBNull = false;//
- dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
- dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
- dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
- DataRow newRow;
- newRow = tblDatas.NewRow();
- newRow["Product"] = "大话西游";
- newRow["Version"] = "2.0";
- newRow["Description"] = "我很喜欢";
- tblDatas.Rows.Add(newRow);
- newRow = tblDatas.NewRow();
- newRow["Product"] = "梦幻西游";
- newRow["Version"] = "3.0";
- newRow["Description"] = "比大话更幼稚";
- tblDatas.Rows.Add(newRow);
- return tblDatas;
- }
- }
复制代码
|