how to find id control inside grdview

Posted by Shanky11 under ASP.NET on 9/27/2012 | Points: 10 | Views : 1268 | Status : [Member] | Replies : 13
griedview>panel>table >tr>td>
i have to find id of label inside td




Responses

Posted by: Jayakumars on: 9/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

refer this
http://forums.asp.net/t/1783033.aspx/2/10
Please mark as answer if it helpful to you.

Mark as Answer if its helpful to you

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Shanky,
try this code.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:ButtonField Text="Try me" CommandName="myRowSelect" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblSample" runat="server" Text='<%#String.Format("Label on row {0}",Ctype(Container,GridViewRow).RowIndex + 1)%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

And relevant code

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "myRowSelect" Then
Dim rowindex As Integer = CInt(e.CommandArgument)
Dim row As GridViewRow = GridView1.Rows(rowindex)
Dim lbl As Label = DirectCast(row.FindControl("lblSample"), Label)

Response.Write("You clicked row having Label with text: " & lbl.Text)

End If
End Sub

Thanks & Regards
Hari

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
Please Mark As Answer if it is useful to u

Thanks & Regards
Hari

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
I WANT TO FETCH ID OF LABEL INSIDE PANEL>TABLE>TR>TD>LABLECONTROL
<asp:GridView ID="gdview1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="1" GridLines="None"
BorderStyle="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Panel ID="panel1" runat="server" BackColor="ControlLight">
<table id="table1" runat="server" style=" width:600px; vertical-align:text-top; padding:5px;" >
<tr id="tr1" runat="server">
<td id="td1" runat="server" align="center">
<asp:ImageMap ID="ImageMap1" ImageUrl="~/images/logo-01 (1).gif" Width="100px" Height="100px" runat="server">
</asp:ImageMap>
</td>
<td id="td2" runat="server">
<asp:ImageMap ID="ImageMap2" ImageUrl="~/images/elevation.gif" Width="230px" Height="100px" runat="server">
</asp:ImageMap>
</td>
<td id="td3" runat="server">
<asp:Label ID="lblpropertyname" runat="server" Text="4 bhk demo"></asp:Label><br/>
<asp:Label ID="lblpropertyprice" runat="server" Text="BSP: Rs 8950/- per sq. ft."></asp:Label>
</td>
</tr>
<tr id="tr2" runat="server">
<td id="td4" runat="server" style=" background-color:Maroon; color:White; text-align:center">
<asp:Label ID="lblcity" runat="server" Text="HYDERABAD"></asp:Label></td>
<td id="td5" runat="server" colspan="2">
<a href=""><asp:Label ID="lbl" Text="Aparna HillPark Avenues Miyapur, Chandanagar, Hyderabad" runat="server"></asp:Label> </a>
</td>

</tr>
<tr id="tr3" runat="server">
<td id="td6" runat="server" colspan="3"><b>Call us on :</b><asp:Label ID="lblcalluson" runat="server" Text="+91-90104 79200"></asp:Label> </td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
I WANT TO FETCH ID OF LABEL INSIDE PANEL>TABLE>TR>TD>LABLECONTROL
<asp:GridView ID="gdview1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="1" GridLines="None"
BorderStyle="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Panel ID="panel1" runat="server" BackColor="ControlLight">
<table id="table1" runat="server" style=" width:600px; vertical-align:text-top; padding:5px;" >
<tr id="tr1" runat="server">
<td id="td1" runat="server" align="center">
<asp:ImageMap ID="ImageMap1" ImageUrl="~/images/logo-01 (1).gif" Width="100px" Height="100px" runat="server">
</asp:ImageMap>
</td>
<td id="td2" runat="server">
<asp:ImageMap ID="ImageMap2" ImageUrl="~/images/elevation.gif" Width="230px" Height="100px" runat="server">
</asp:ImageMap>
</td>
<td id="td3" runat="server">
<asp:Label ID="lblpropertyname" runat="server" Text="4 bhk demo"></asp:Label><br/>
<asp:Label ID="lblpropertyprice" runat="server" Text="BSP: Rs 8950/- per sq. ft."></asp:Label>
</td>
</tr>
<tr id="tr2" runat="server">
<td id="td4" runat="server" style=" background-color:Maroon; color:White; text-align:center">
<asp:Label ID="lblcity" runat="server" Text="HYDERABAD"></asp:Label></td>
<td id="td5" runat="server" colspan="2">
<a href=""><asp:Label ID="lbl" Text="Aparna HillPark Avenues Miyapur, Chandanagar, Hyderabad" runat="server"></asp:Label> </a>
</td>

</tr>
<tr id="tr3" runat="server">
<td id="td6" runat="server" colspan="3"><b>Call us on :</b><asp:Label ID="lblcalluson" runat="server" Text="+91-90104 79200"></asp:Label> </td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sureshknkt7 on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

The following Code useful to you,

Foreach(Gridviewrow row in gdview1.Rows)
{
Label lblid = (Label)row.findcontrol("lblpropertyname");

}

By using above Label Id(lblid) you can get attributes of label like
lblid.Text


Thank You,
Suresh

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
Foreach(Gridviewrow row in gdview1.Rows)
wha is Gridviewrow its shoeing erroe in this line
not findind Gridviewrow

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
protected void Button1_Click(object sender, EventArgs e)
{
Foreach(Gridviewrow row in gdview1.Rows)
{
Label lblid = (Label)row.findcontrol("lblpropertyname");

}
}

By using above Label Id(lblid) you can get attributes of label like
lblid.Text


Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
shanky 11

try this

if (!IsPostBack)
{
sqlcon.Open();
SqlDataAdapter sqladp = new SqlDataAdapter("select * from [employee]", sqlcon);
sqladp.Fill(dt);
gdview1.DataSource = dt;
gdview1.DataBind();
}

foreach (GridViewRow row in gdview1.Rows)
{
Label lblid = (Label)row.FindControl("lblpropertyname");
Response.Write(lblid.Text);
}

this is working for me.

Donot Forgot
Please Mark As Answer if it is useful to u

Mark as Answer if its helpful to you

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 9/27/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
Control ctrl = e.CommandSource as Control;
if (ctrl != null)
{
GridViewRow gvRow = ctrl.Parent.NamingContainer as GridViewRow;
Label slno = (Label)gvRow.FindControl("slno"); // Find Your Control here
TextBox txtno = (TextBox)gvRow.FindControl("txtno"); // Find Your Control here
// Your work start here
}
}



Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
i have a griedview inside that panel in that table tr td then label is theere
from there i hav to to fetch id of that lable so i acn bind data accorrd to my req.
i hav to bind on load


Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
row command works when there is a button inside a griedview a we click it.
this is not my problem
my problem is i hav a gridview >panel >table>tr>td>inside that a label i have to fetch the id of label

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 9/27/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,

foreach (GridViewRow rw in GridView1.Rows) // GridView1 is your Gridview name
{
Label lbl = (Label)rw.FindControl("YourLabelName"); // Find ur control here

if (lbl != null)
{
string ID = lbl.Text; // Get ur id here.
}
}



Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response