Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DropDownList In GridView problem
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
DropDownList In GridView problem
Miscellaneous
Thread ID:
01455784
Message ID:
01455784
Views:
84
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.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform