ASP.NET中通过GRIDVIEW"选择"的按钮将数据显示到TEXTBOX中
2008-11-16 13:05
531 查看
HTML代码:
<asp:GridView ID="GridView1" runat="server" DataKeyNames="ckdh" Height="183px" Style="left: 0px; position: relative;
top: -18px; font-size: small;" Width="864px" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
AutoGenerateSelectButton="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" EmptyDataText="未录入">
<PagerStyle HorizontalAlign="Right" BackColor="#FFCC66" ForeColor="#333333"/>
<PagerSettings Mode="NextPreviousFirstLast" FirstPageText="第一页" PreviousPageText="上一页" NextPageText="下一页" LastPageText="最后一页" />
<Columns>
<asp:BoundField DataField="ckdh" HeaderText="出库单号" SortExpression="ckdh" />
<asp:BoundField DataField="ckkb" HeaderText="出库库别" SortExpression="ckkb" />
<asp:BoundField DataField="ypqx" HeaderText="药品去向" SortExpression="ypqx" />
<asp:BoundField DataField="ypbh" HeaderText="药品编号" SortExpression="ypbh" />
<asp:BoundField DataField="ypmc" HeaderText="药品名称" SortExpression="ypmc" />
<asp:BoundField DataField="gg" HeaderText="药品规格" SortExpression="gg" />
<asp:BoundField DataField="dw" HeaderText="药品单位" SortExpression="dw" />
<asp:BoundField DataField="sj" HeaderText="出库价格" SortExpression="sj" />
<asp:BoundField DataField="sl" HeaderText="出库数量" SortExpression="sl" />
</Columns>
<SelectedRowStyle ForeColor="Navy" BackColor="#FFCC66" Font-Bold="True" />
<RowStyle ForeColor="#333333" BackColor="#FFFBD6" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
C#后台代码:
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs a)
{
TextBox1.Text = GridView1.Rows[a.NewSelectedIndex].Cells[1].Text.ToString();
TextBox2.Text = GridView1.Rows[a.NewSelectedIndex].Cells[2].Text.ToString();
TextBox3.Text = GridView1.Rows[a.NewSelectedIndex].Cells[3].Text.ToString();
TextBox4.Text = GridView1.Rows[a.NewSelectedIndex].Cells[4].Text.ToString();
TextBox5.Text = GridView1.Rows[a.NewSelectedIndex].Cells[5].Text.ToString();
TextBox6.Text = GridView1.Rows[a.NewSelectedIndex].Cells[6].Text.ToString();
TextBox7.Text = GridView1.Rows[a.NewSelectedIndex].Cells[7].Text.ToString();
TextBox8.Text = GridView1.Rows[a.NewSelectedIndex].Cells[8].Text.ToString();
TextBox9.Text = GridView1.Rows[a.NewSelectedIndex].Cells[9].Text.ToString();
Session["shuliang"] = Convert.ToInt32( TextBox9.Text);
//TextBox10.Text = GridView1.Rows[e.NewSelectedIndex].Cells[10].Text.ToString();
//TextBox11.Text = GridView1.Rows[e.NewSelectedIndex].Cells[11].Text.ToString();
// TextBox1.Text = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text.ToString();
//Response.Write("<h1>" + sl + "</h1>");
//bh = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text.ToString(); //得到选中行第二个单元格的文本
}
话费充值http://cn008.taobao.com
<asp:GridView ID="GridView1" runat="server" DataKeyNames="ckdh" Height="183px" Style="left: 0px; position: relative;
top: -18px; font-size: small;" Width="864px" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
AutoGenerateSelectButton="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" EmptyDataText="未录入">
<PagerStyle HorizontalAlign="Right" BackColor="#FFCC66" ForeColor="#333333"/>
<PagerSettings Mode="NextPreviousFirstLast" FirstPageText="第一页" PreviousPageText="上一页" NextPageText="下一页" LastPageText="最后一页" />
<Columns>
<asp:BoundField DataField="ckdh" HeaderText="出库单号" SortExpression="ckdh" />
<asp:BoundField DataField="ckkb" HeaderText="出库库别" SortExpression="ckkb" />
<asp:BoundField DataField="ypqx" HeaderText="药品去向" SortExpression="ypqx" />
<asp:BoundField DataField="ypbh" HeaderText="药品编号" SortExpression="ypbh" />
<asp:BoundField DataField="ypmc" HeaderText="药品名称" SortExpression="ypmc" />
<asp:BoundField DataField="gg" HeaderText="药品规格" SortExpression="gg" />
<asp:BoundField DataField="dw" HeaderText="药品单位" SortExpression="dw" />
<asp:BoundField DataField="sj" HeaderText="出库价格" SortExpression="sj" />
<asp:BoundField DataField="sl" HeaderText="出库数量" SortExpression="sl" />
</Columns>
<SelectedRowStyle ForeColor="Navy" BackColor="#FFCC66" Font-Bold="True" />
<RowStyle ForeColor="#333333" BackColor="#FFFBD6" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
C#后台代码:
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs a)
{
TextBox1.Text = GridView1.Rows[a.NewSelectedIndex].Cells[1].Text.ToString();
TextBox2.Text = GridView1.Rows[a.NewSelectedIndex].Cells[2].Text.ToString();
TextBox3.Text = GridView1.Rows[a.NewSelectedIndex].Cells[3].Text.ToString();
TextBox4.Text = GridView1.Rows[a.NewSelectedIndex].Cells[4].Text.ToString();
TextBox5.Text = GridView1.Rows[a.NewSelectedIndex].Cells[5].Text.ToString();
TextBox6.Text = GridView1.Rows[a.NewSelectedIndex].Cells[6].Text.ToString();
TextBox7.Text = GridView1.Rows[a.NewSelectedIndex].Cells[7].Text.ToString();
TextBox8.Text = GridView1.Rows[a.NewSelectedIndex].Cells[8].Text.ToString();
TextBox9.Text = GridView1.Rows[a.NewSelectedIndex].Cells[9].Text.ToString();
Session["shuliang"] = Convert.ToInt32( TextBox9.Text);
//TextBox10.Text = GridView1.Rows[e.NewSelectedIndex].Cells[10].Text.ToString();
//TextBox11.Text = GridView1.Rows[e.NewSelectedIndex].Cells[11].Text.ToString();
// TextBox1.Text = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text.ToString();
//Response.Write("<h1>" + sl + "</h1>");
//bh = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text.ToString(); //得到选中行第二个单元格的文本
}
话费充值http://cn008.taobao.com
相关文章推荐
- ASP.NET的gridview设置数据格式(DataFormatString="{}")
- ASP.NET的gridview设置数据格式(DataFormatString="{}")与 String.Format 使用总结
- asp.net系统导入Excel数据时提示:未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0” 提供程序"
- asp.net利用GridView"表中表"实现主从表数据
- 在ASP.NET中使用ObjectDataSource数据控件和GridView显示数据
- ASP.NET中通过文本框的输入实现"拼音码"动态查询的效果
- ASP.NET 2.0:通过SqlDataSource绑定数据到普通控件
- Asp.net MVC 示例项目"Suteki.Shop"分析之---数据验证
- Control Study -> Asp.net几个较复杂的显示数据控件(Repeater/DataList/DataGrid)用法 (示例代码下载)
- Asp.net页面之间通过脚本传递数据 选择自 hushan518 的 Blog
- asp.net中父子页面通过gridview中的按钮事件进行回传值的问题
- [翻译]Scott Mitchell 的ASP.NET 2.0数据教程之十五:在GridView的页脚中显示统计信息
- ASP.NET中TextBox控件设置ReadOnly="true"后台取不到值
- asp.net<Web版> ---GridView 数据导出到excel表,系列问题<一>---导出的Excel文件格式与文件扩展名指定的格式不一致
- ASP.NET 中TextBox设置ReadOnly="true" 无法取到值的做法
- 关于Asp.net中GridView控件不显示部分列数据的方法
- ASP.NET Entity Framework 查询数据表多个"s"的解决方法。
- 如何让Gridview在没有数据的时候显示表头(asp.net)
- 在ASP.NET 2.0中操作数据之十五:在GridView的页脚中显示统计信息
- Asp.net GridView 无数据时也显示列名