>>>>I have a DropDownList in a DGV on my page"
>>>>
>>>>
>>>><asp:GridView ID="GridView1"
>>>> runat="server"
>>>> AutoGenerateColumns="False">
>>>>
>>>> <Columns>
>>>>
>>>> <asp:BoundField DataField="RightKey" HeaderText="RightKey" />
>>>>
>>>> <asp:TemplateField HeaderText="Allow / Deny">
>>>> <ItemTemplate>
>>>> <asp:DropDownList DataSource='<# GetAllowDenyValues() >' DataTextField="AllowDeny"
>>>> DataValueField="AllowDeny" ID="AllowDeny" runat="server"></asp:DropDownList>
>>>> </ItemTemplate>
>>>> </asp:TemplateField>
>>>>
>>>> <asp:BoundField DataField="RightName" HeaderText="Right Name" />
>>>>
>>>> </Columns>
>>>>
>>>></asp:GridView>
>>>>
>>>>
>>>>I'm then doing this in the C# code:
>>>>
>>>>
>>>>private string ConnectionString = string.Empty;
>>>>
>>>>protected void Page_Load(object sender, EventArgs e)
>>>>{
>>>> if (!IsPostBack)
>>>> {
>>>> ConnectionString = ConfigurationManager.ConnectionStrings["MyConnStr"].ConnectionString;
>>>> BindData();
>>>> }
>>>>}
>>>>
>>>>public DataSet GetAllowDenyValues()
>>>>{
>>>> SqlConnection myConnection = new SqlConnection(ConnectionString);
>>>> SqlDataAdapter ad = new SqlDataAdapter("SELECT DISTINCT CASE WHEN AllowDeny = 0 " +
>>>> " THEN 'No' WHEN AllowDeny = 1 THEN 'Yes'END AS AllowDeny FROM sec_Rights ", myConnection);
>>>> DataSet ds = new DataSet();
>>>> ad.Fill(ds, "AllowDeny");
>>>> return ds;
>>>>}
>>>>
>>>>private void BindData()
>>>>{
>>>> SqlConnection conn = new SqlConnection(ConnectionString);
>>>> SqlParameter pUserKey = new SqlParameter("@UserKey", 2);
>>>> SqlCommand cmd = new SqlCommand();
>>>> cmd.Parameters.Add(pUserKey);
>>>> cmd.Connection = conn;
>>>> cmd.CommandText = "as_GetRightsForUserEx";
>>>> cmd.CommandType = CommandType.StoredProcedure;
>>>>
>>>> SqlDataAdapter ad = new SqlDataAdapter();
>>>> ad.SelectCommand = cmd;
>>>> DataSet ds = new DataSet();
>>>> ad.Fill(ds, "Rights");
>>>> GridView1.DataSource = ds;
>>>> GridView1.DataBind();
>>>>}
>>>>
>>>>
>>>>
>>>>The DropDownList is being loaded ok, but all columns show 'No'. The column is not respecting the data's AllowDeny column which
>>>>is INT(1 or 0). Only one of the 5 rows being returned in my test actually have a 0 in it.
>>>
>>>Where are you getting five rows from? The SQL should only return two (assuming there's at least one 1 and one 0 and no other values in the AllowDeny column....
>>
>>The 5 rows are returned from the call to the stored proc as_GetRightsForUserEx in BindData. The Yes/No are only the allowable values for the AllowDeny column in the grid.
>
>It's not too clear what you're trying to do - but it looks overly complicated :-}
>Instead of getting the Listtems for the DropDownList from the DB would something like this work:
<asp:TemplateField HeaderText="Allow / Deny">
> <ItemTemplate>
> <asp:DropDownList Id="AllowDeny" runat="server"
> SelectedValue='< %# Bind("AllowDeny") % >' >
> <asp:ListItem Value="1">Yes</asp:ListItem>
> <asp:ListItem Value="0">No</asp:ListItem>
> </asp:DropDownList>
> </ItemTemplate>
></asp:TemplateField>
What I want to do is create a grid with the name of an access right and a combo that says "Yes" or "No". In the dataset there is a
column called AllowDeny with 1 or 0. I want the combo to be bound to the AllowDeny column, so that for each row, Yes shows if
the AllowDeny column has a 1 in it, and "No" shows if AllowDeny is 0.
I could also use a checkbox if that's easier.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people