Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a grid view.
in grid view have :
ASP.NET
<asp:Label ID="IdTopic" runat="server" Text='<%# Eval("IDTopic") %>' Visible="false"></asp:Label>

out of grid view have :
ASP.NET
<asp:Label ID="lb1" runat="server" ></asp:Label>

i want get text from IdTopic and set on lb1.
all of them are into content page of master page.
in master page i writr this code:
JavaScript
function setLabel() {
           
            var IdTopictxt = $("#IdTopic").val;
            $("#lb1").text(IdTopictxt);


        }


in code-behind:c#
C#
ContentPlaceHolder cp = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder2");
            
            Label lb = (Label)cp.FindControl("IdTopic");
            if (lb != null)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "ShowAlert();", true);
                mytxt.Text = lb.Text.ToString();

            }

my alert show but don,t show any in myTxt.
how i can do ?
Posted

 
Share this answer
 
this code help me but don,t work:
C#
foreach(GridViewRow row in gv.Rows)
{
    TextBox txtTotal = row.cells[0].Controls[0].FindControl("TOTAL") as TextBox;
    string value = txtTotal.Text;

    // Do something with the textBox's value
}

i changed code :
C#
ContentPlaceHolder cp = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder2");
GridView gv = (GridView)cp.FindControl("showPostrRGridView");
foreach (GridViewRow row in gv.Rows)
{
    Label txtTotal = row.FindControl("IdTopic") as Label;
    string value = txtTotal.Text;
    lb1.Text = value;
}


thank you for help me .
 
Share this answer
 
my problem solved .

http://forums.asp.net/t/1537390.aspx?ASP+NET+C+How+to+get+the+cell+index+of+gridview+in+the+event+selectindexchanged+[^]
i should changed code :
ASP.NET
<asp:LinkButton ID="linkToPost" CommandName="ltp" Text='<%# Eval("titleTopic") %>' Font-Size="Large" Font-Names="b yekan" runat="server" ForeColor="#c6c574" OnClick="linkToPost_Click"></asp:LinkButton></td>

and
C#
protected void showPostrRGridView_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           if (e.CommandName == "ltp")
           {
              LinkButton linkbtn=(LinkButton)e.CommandSource;

                   lb1.Text = linkbtn.Text;

               }
           }
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900