FineUI 官方论坛
标题:
GRID中使用ASP的DropDownList控件,OnSelectedIndexChanged只对第一行起
[打印本页]
作者:
大鸟打小鸟
时间:
2012-12-29 09:23
标题:
GRID中使用ASP的DropDownList控件,OnSelectedIndexChanged只对第一行起
三石大人您好!我在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;
}
}
复制代码
[attach]1528[/attach]
[attach]1529[/attach]
作者:
sanshi
时间:
2012-12-31 21:02
测试了一下,两行中的下拉列表都能触发,只不过在更新模板列之后,要手工调用 UpdateTemplateFields:
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;
gridTest.UpdateTemplateFields();
}
复制代码
[attach]1534[/attach]
作者:
大鸟打小鸟
时间:
2013-1-2 13:16
原来如此,谢谢三石了{:soso_e100:}
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4