I am using a GridView and in it I have four columns: labelID, fName, lName and Grade. The Grade is a simple Pass or Fail Radiobuttonlist. Once the data is updated I would like it to pull the data on the next reload to show the selected value if the user has passed or failed. Here is the code:
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButtonList ID="rblChoices" runat="server" OnSelectedIndexChanged="rblChoices_SelectedIndexChanged" Text='<%# Eval("Grade") %>'>
<asp:ListItem Value="Pass" Text="Pass"></asp:ListItem>
<asp:ListItem Value="Fail" Text="Fail"></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
C# code:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
private void BindData()
{
string connectiongString = "Data Source=WSCJTCSQ1;Initial Catalog=LiquorStore;Integrated Security=True";
SqlConnection myConnection = new SqlConnection(connectiongString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT id, firstname, lastname, nickname, Grade FROM Company", myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
gvUsers.DataSource = ds;
gvUsers.DataBind();
}
Thank you in advance!
You have to use the GridView RowDataBound event for this
HTML
C# Code
A very simple company class – Company.cs
.aspx.cs
OUTPUT