代码如下: <ext:Grid ID="Grid1" ShowBorder="true" ShowHeader="true" Title="表格" Width="800px"
runat="server" DataKeyNames="Id,xmmc">
<Columns>
<ext:BoundField Width="100px" DataField="xmmc" DataFormatString="{0}" HeaderText="名称" />
<ext:BoundField Width="60px" DataField="jldw" HeaderText="单位" />
<ext:TemplateField HeaderText="分组" Width="100px">
<ItemTemplate>
<asp:TextBox ID="tbxZcb" runat="server" Width="80px" TabIndex='<%# Container.DataItemIndex + 10 %>'
Text='<%# Eval("zcb") %>'></asp:TextBox>
</ItemTemplate>
</ext:TemplateField>
</Columns>
</ext:Grid>
<ext:Button runat="server" ID="Button1" OnClick="Button1_Click" Text="获取用户输入的分组值">
</ext:Button>
<br />
<extabel ID="labResult" EncodeText="false" runat="server">
</extabel>
<br />
</form>
<script type="text/javascript">
var gridClientID = '<%= Grid1.ClientID %>';
function registerSelectEvent() {
var grid = X(gridClientID);
grid.el.select('.x-grid-tpl input').on('click', function (evt, el) {
el.select();
});
}
function onReady() {
var grid = X(gridClientID);
grid.on('viewready', function () {
registerSelectEvent();
});
}
function onAjaxReady() {
registerSelectEvent();
}
</script>
StringBuilder sb = new StringBuilder();
sb.Append("<table style=\"width:350px;\"><tr><th>编号</th><th>姓名</th><th>用户输入的分组号</th></tr>");
for (int i = 0, count = Grid1.Rows.Count; i < count; i++)
{
sb.Append("<tr>");
object[] rowDataKeys = Grid1.DataKeys[i];
sb.AppendFormat("<td>{0}</td>", rowDataKeys[0]);
sb.AppendFormat("<td>{0}</td>", rowDataKeys[1]);
GridRow row = Grid1.Rows[i];
System.Web.UI.WebControls.TextBox tbxGroupName = (System.Web.UI.WebControls.TextBox)row.FindControl("tbxZcb");
sb.AppendFormat("<td>{0}</td>", tbxGroupName.Text);
sb.Append("<tr>");
}
sb.Append("</table>");
labResult.Text = sb.ToString();
} |