Hi @Kris Ellison,
You'd better provide your code so that we can help you more specifically.
Below are two methods of getting columns that I wrote according to your needs.
protected void Button1_Click(object sender, EventArgs e)
{
List<int> numbers = new List<int>();
List<int> number = new List<int>();
for (int i = 0; i < gvCustomers.Rows.Count; i++)
{
//get the second column
int a = Convert.ToInt32(gvCustomers.Rows[i].Cells[1].Text);
if (a > 10)
{
numbers.Add(a);
Label1.Text = string.Join(",", numbers);
}
//get the third column
TextBox tb = (TextBox)gvCustomers.Rows[i].FindControl("TextBox1");
int b = Convert.ToInt32(tb.Text.ToString());
if (b > 10)
{
number.Add(b);
Label2.Text = string.Join(",", number);
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("CustomerId"),
new DataColumn("Name"),
new DataColumn("Country")
});
dt.Rows.Add(1, 1, 11);
dt.Rows.Add(2, 22, 2);
dt.Rows.Add(3, 12, 0);
dt.Rows.Add(4, 3, 13);
gvCustomers.DataSource = dt;
gvCustomers.DataBind();
}
}
<div>
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="CustomerId" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Country">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Country") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</div>
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.