<asp:GridView ID="GridView1" runat="server"
OnDataBound="GridView1_DataBound"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
AutoGenerateColumns="False" >
<Columns>
<asp:CheckBoxField DataField="isChecked" HeaderText="Select" />
<asp:BoundField DataField="Value" HeaderText="Value" />
<asp:TemplateField HeaderText="Custom Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Once the user edits the Custom Select checkboxes and pushes the button (btnSumbit), I read which fields are checked. If checked, I read from a Hashtable the value associated with the key.
protected void btnSubmit_Click(object sender, EventArgs e)
{
string sQueryString = "http://foo?";
// load hashtable with key values
Hashtable vhtTags = (Hashtable)Cache["htTags"];
bool isChecked;
// parse through to see what values are selected in gridview
foreach (GridViewRow vRow in GridView1.Rows)
{
isChecked = ((CheckBox)vRow.FindControl("chkSelect")).Checked;
if (isChecked)
{
string skey = vRow.Cells[1].Text.Trim();
sQueryString += vhtTags[skey].ToString();
}
}
lblResult.Text = sQueryString;
}
}
Notes: Since the first check column is only for demonstration and the last column is not bound because the default values are false. For the sake of brevity, error checking is left out.
Reference: link