>><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> >>>>
>>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(); >>} >> >>>>