所选单元格的值未显示在文本框中. [英] The selected cell value is not displaying in the text box.

查看:80
本文介绍了所选单元格的值未显示在文本框中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我只是从asp.net的数据库中的网格视图中打印输出值.我需要在按钮单击事件的文本框中打印特定单元格的值.我只是应用了以下代码.它没有给出任何错误.该值未显示在文本框中.您能说出为什么会发生这种情况吗?


I just print print the values in the grid view from database in asp.net.I need to print the value of a particular cell in the text box on the button click event.I just applied the following code.it gives no error.But the value is not displaying in the textbox.Could you tell why is this happening?

GridView1.SelectedIndex = 0;
        TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;

推荐答案

存在索引选择问题,您应该以这种方式编写代码,我认为这将对你.
代码隐藏
受保护的void GridView1_RowCommand(对象发送者,GridViewCommandEventArgs e)
{
如果(e.CommandName =="cmdBind")
{
LinkBut​​ton lb =(LinkBut​​ton)e.CommandSource;
int索引= Convert.ToInt32(lb.CommandArgument);

TextBox3.Text = GridView1.Rows [index] .Cells [2] .Text.ToString();

TextBox4.Text = GridView1.Rows [index] .Cells [3] .Text.ToString();
txtplantname.Text = GridView1.Rows [index] .Cells [4] .Text;
TextBox1.Text = GridView1.Rows [index] .Cells [5] .Text;
Label1.Text = GridView1.Rows [index] .Cells [6] .Text;
}
}
受保护的void GridView1_PageIndexChanging(对象发送者,GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
//GridData();
}
设计鳕鱼 e
< asp:gridview id ="GridView1" runat ="server" bordercolor =#8080FF" width ="100%" onrowcommand ="GridView1_RowCommand" onpageindexchanging ="GridView1_PageIndexChanging" onselectedindexchanged ="GridView1_SelectedIndexChanged" xmlns:asp =#unknown" >
< columns>< asp:templatefield headertext ="Details">
< itemtemplate>
< asp:linkbutton id ="lnkDet" commandname ="cmdBind" commandargument =<%#((GridViewRow)容器).RowIndex%>" runat ="server" Causesvalidation ="false">查看详细信息


There is Index Selection Problem, You Should be write your code this way, I think This will be helpfull for you.
CodeBehind
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cmdBind")
{
LinkButton lb = (LinkButton)e.CommandSource;
int index = Convert.ToInt32(lb.CommandArgument);

TextBox3.Text = GridView1.Rows[index].Cells[2].Text.ToString();

TextBox4.Text = GridView1.Rows[index].Cells[3].Text.ToString();
txtplantname.Text = GridView1.Rows[index].Cells[4].Text;
TextBox1.Text = GridView1.Rows[index].Cells[5].Text;
Label1.Text = GridView1.Rows[index].Cells[6].Text;
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
//GridData();
}
Designing Code
<asp:gridview id="GridView1" runat="server" bordercolor="#8080FF" width="100%" onrowcommand="GridView1_RowCommand" onpageindexchanging="GridView1_PageIndexChanging" onselectedindexchanged="GridView1_SelectedIndexChanged" xmlns:asp="#unknown">
<columns><asp:templatefield headertext="Details">
<itemtemplate>
<asp:linkbutton id="lnkDet" commandname="cmdBind" commandargument="<%# ((GridViewRow) Container).RowIndex %>" runat="server" causesvalidation="false">View Details



检查单元格.首先检查网格中有多少个单元格.
我会给你样品.我有一个gridview和文本框.

Your check your cells.First you check how many cells in your grid.
i will give you sample. I have one gridview and textbox.

ArrayList arr = new ArrayList();
            arr.Add("AA");
            arr.Add("BB");
            arr.Add("CC");

            GridView1.DataSource = arr;
            GridView1.DataBind();
            GridView1.SelectedIndex = 0;
            TextBox1.Text = GridView1.SelectedRow.Cells[0].Text.Trim();


你这样检查.

希望对您有所帮助,
Theingi Win.


You check like this.

Hope be helpful,
Theingi Win.


这篇关于所选单元格的值未显示在文本框中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆