如何在网格中单击按钮以获取垂直细胞值 [英] how to get perticular cell value on button click which is in grid veiw
问题描述
我有一个带有按钮字段的gridview
当我单击一个按钮时,应该使面板可见,而该面板不在网格内,同时我想访问该垂直行的单元格值之一
在网格中,我正在显示
辅助cid cname名称和按钮字段
当我按一下按钮时,panal应该可见,并且我希望cid值存储在一个变量中.
这是我的网格
I have a gridview with a button field
when I click on a button it should make the panel visible which is out of grid and at the same time I want to access one of the cell value of that perticular row
in the grid i am displaying
aid cid cname aname and a button field
when i clck on a button the panal should be visible and i want the cid value to be stored in one variable.
this is my grid
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="onselectedindex">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Appointment Id">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Appointment_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Appointment date">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("Appointment_Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Start Time">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%#Eval("Start_Time") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="End Time">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#Eval("End_Time") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Consumer Id" Visible="false">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%#Eval("Consumer_Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Consumer Name">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%#Eval("First_Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="No. Of Friends">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%#Eval("NO_OF_FRIENDS") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button2" runat="server" Text="Deploy" OnClick="btn_click" /></ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
这是代码
and this is the code
protected void btn_click(object sender, EventArgs e)
{
Panel1.Visible = true;
int cid = Convert.ToInt32(GridView1.SelectedRow.Cells[4].Text);
Lblcid.Text = cid.ToString();
}
请帮忙.
please help .
推荐答案
尝试:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CommandArgument='<%#Eval("consumer_id")%>' Text="Submit" OnClick="Button1_Click" />
</ItemTemplate>
</asp:TemplateField>
然后,您可以在后面的代码中像这样检索它:
You can then retrieve it like this in the code behind:
protected void Button1_Click(object sender, EventArgs e)
{
Button myButton = sender as Button;
if (myButton != null)
{
string consumerID = myButton.CommandArgument;
// use this title now to set as a text for your label.
// use the consumer id
// show the needed panel
}
}
发送者持有对触发事件处理程序的Button
的引用.
The sender holds a reference to the Button
that triggered the event handler.
这篇关于如何在网格中单击按钮以获取垂直细胞值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!