当我单击链接按钮时,我想在标签中显示数据 [英] When i click the link button i want to display the data in the label

查看:99
本文介绍了当我单击链接按钮时,我想在标签中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有datagridview的格式,其中im在一列中使用链接按钮... im从数据库中获取数据...当我单击链接按钮时,我要显示在该单元格中找到的数据.在标签中显示...

Im having datagridview in the form in which im using link button in one column...im fetching data from the database...when i click the link button i want to display the data found in that cell..the data is displayed in the label...

推荐答案

通过以下方式使用链接按钮
use the link button in a following way
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Xeshan's Link Button



并在后面的代码中定义click事件,只需解析发送方以链接按钮并获取其文本



and in code behind define the click event and simply parse sender to link button and get its text

protected void LinkButton1_Click(object sender, EventArgs e)
{
   //This is text of your link button
  //((LinkButton)sender).Text;
}


<asp:TemplateField HeaderText="Select">
                           <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Fetch </asp:LinkButton>

                           </asp:TemplateField>




后面的代码




code behind

protected void LinkButton1_Click(object sender, EventArgs e)
   {
      lbl1.Text = GridView1.SelectedRow.Cells[1].Text;
      lbl2.Text = GridView1.SelectedRow.Cells[2].Text;
   }




Yogesh.




Yogesh.


<asp:gridview id="GridView1" runat="server" 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
                </itemtemplate>
                       
            </columns>


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "cmdBind")
    {
        LinkButton lb = (LinkButton)e.CommandSource;
        int index = Convert.ToInt32(lb.CommandArgument);

        //Bind values in the text box of the pop up control
        TextBox3.Text    = GridView1.Rows[index].Cells[3].Text.ToString();
        TextBox4.Text    = GridView1.Rows[index].Cells[3].Text.ToString();
        TextBox7.Text = GridView1.Rows[index].Cells[4].Text;
        Label7.Text = GridView1.Rows[index].Cells[1].Text;
        Label9.Text=GridView1.Rows[index].Cells[1].Text;
        TextBox8.Text = GridView1.Rows[index].Cells[6].Text;
        TextBox6.Text = GridView1.Rows[index].Cells[2].Text;
        TextBox5.Text = GridView1.Rows[index].Cells[6].Text;
    }
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    //GridData();
}


这篇关于当我单击链接按钮时,我想在标签中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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