Gridview Error on editing with dropdownlist - asp.net

I have grid view with folowing complete code With Msaccess DB.I have used the decode function in sql query.When i press the edit button on grid view it shows folowing error
"DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
My SQL Data source code is below
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString2 %>"
DeleteCommand="DELETE FROM [EMAILS] WHERE [ID] = ?" InsertCommand="INSERT INTO [EMAILS] ([Email], [FULLNAME],[FLAG]) VALUES (?, ?, ?)"
ProviderName="<%$ ConnectionStrings:DataConnectionString2.ProviderName %>" SelectCommand="SELECT ID, Email, FULLNAME, switch(FLAG = 1, 'Allowed', Flag = 0, 'Not Allowed') AS FLAG FROM EMAILS"
UpdateCommand="UPDATE [EMAILS] SET [Email] = ?, [FULLNAME] = ?,[FLAG] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="FLAG" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="FLAG" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
And Grid View Code is bellow
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1"
HorizontalAlign="Center" Width="821px" EmptyDataText="No Emails Found">
<RowStyle BackColor="White" Font-Names="Arial" Font-Size="Small" ForeColor="Black" />
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="True" ShowSelectButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" Visible="False" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="FULLNAME" HeaderText="Full Name" SortExpression="FULLNAME" />
<asp:TemplateField HeaderText="Flag" SortExpression="FLAG">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue="<%# Bind('FLAG') %>" AppendDataBoundItems="True">
<asp:ListItem Value="1">Allowed</asp:ListItem>
<asp:ListItem Value="0">Not Allowed</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FLAG") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<HeaderStyle BackColor="#990000" Font-Bold="True" Font-Names="Arial" Font-Size="Small"
ForeColor="#FFFFCC" HorizontalAlign="Center" />
<EmptyDataRowStyle BackColor="#804000" Font-Names="Arial" Font-Size="Small" ForeColor="White" />
</asp:GridView>
Please tell me what possible error is here

Check weather the value in Field flag of the row you are trying to edit, is available in the DropDownList in EditItemTemplate
And try removing AppendDataBoundItems="True" in DropDownList in EditItemTemplate

Related

ASP.NET DropDownList used in AccessDataSource SelectCommand?

Tried adding SelectParameter with drop down selected. Page doesn't fail but class name is not filtered out - not accepting Parameter #ClassName The Affiliation Parameter works fine, but #ClassName does not!
WHERE ClassName = #ClassName
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1" BackColor="White" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black"
GridLines="Vertical" AllowSorting="True">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="RowLevelCheckBox" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UsersDataTbl.StudentID" HeaderText="FDID" SortExpression="StudentID" />
<asp:BoundField DataField="UsersDataTbl.LastName" HeaderText="Last Name" SortExpression="LastName" />
<asp:BoundField DataField="UsersDataTbl.FirstName" HeaderText="First Name" SortExpression="FirstName" />
<asp:BoundField DataField="UsersDataTbl.UserName" HeaderText="User Name" SortExpression="UserName" />
<asp:BoundField DataField="UsersDataTbl.Affiliation" HeaderText="Affiliation" SortExpression="Affiliation" />
<asp:BoundField DataField="UsersDataTbl.UID" HeaderText="UID" SortExpression="UID" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#6699CC" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="<%$ ConnectionStrings:AccessSubSiteString %>"
SelectCommand="SELECT [UsersDataTbl.StudentID], [UsersDataTbl.UserName],
[UsersDataTbl.LastName], [UsersDataTbl.FirstName], [UsersDataTbl.Affiliation], [UsersDataTbl.UID]
FROM [UsersDataTbl] WHERE [UsersDataTbl.Active] = True AND (UsersDataTbl.Affiliation = #Affiliation)
AND ([UsersDataTbl.UID] NOT IN (SELECT UID FROM [EnrollmentsTbl] WHERE ClassName = #ClassName AND Completed = True))
ORDER BY [UsersDataTbl.LastName]" >
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" Name="Affiliation" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DropDownList1" Name="ClassName" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:AccessDataSource>
Not sure why but reversing the order of the ControlParameter fixed the issue, moved ClassName above Affiliation resolved the issue... any ideas why?
<asp:ControlParameter ControlID="DropDownList1" Name="ClassName" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DropDownList2" Name="Affiliation" PropertyName="SelectedValue" Type="String" />

Dropdown List issue in ASP.net gridview edit mode

I have a asp.net gridview that is giving me fits. I'm pulling the data into the grid with no issues. However, when I click edit, I get this error:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'wrkCode'.
My intention is to allow the user to edit a group's work schedule using a dropdown list. Here is my code:
<asp:GridView ID="grdShowGroups" runat="server" datakeynames="grpID" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="5" GridLines="Vertical" CellSpacing="5" Width="700px" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="grdShowGroups_SelectedIndexChanged">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" HeaderText="Edit" />
<asp:BoundField DataField="grpID" HeaderText="grpID" SortExpression="grpID" InsertVisible="False" ReadOnly="True" Visible="false" />
<asp:BoundField DataField="grpStartTime" HeaderText="Start Time" SortExpression="grpStartTime" />
<asp:BoundField DataField="grpEndTime" HeaderText="End Time" SortExpression="grpEndTime" />
<asp:TemplateField HeaderText="Work Schedule" SortExpression="wrkSchedule">
<EditItemTemplate>
<asp:DropDownList ID="drpWrkSchedule" runat="server" DataSourceID="SqlDataSource2" DataTextField="wrkDescription" DataValueField="wrkCode" SelectedValue='<%#Bind("wrkCode")%>' AppendDataBoundItems="true" AutoPostBack="true"></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblWrkSchedule" runat="server" Text='<%# Bind("wrkSchedule") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="grpDescription" HeaderText="Description" SortExpression="grpDescription" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EmployeeMGTConnectionString %>" SelectCommand="SELECT [grpID], [grpStartTime], [grpEndTime], [wrkSchedule], [grpDescription] FROM [empGroups]" DeleteCommand="DELETE FROM [empGroups] WHERE [grpID] = #grpID" InsertCommand="INSERT INTO [empGroups] ([grpStartTime], [grpEndTime], [wrkSchedule], [grpDescription]) VALUES (#grpStartTime, #grpEndTime, #wrkSchedule, #grpDescription)" UpdateCommand="UPDATE [empGroups] SET [grpStartTime] = #grpStartTime, [grpEndTime] = #grpEndTime, [wrkSchedule] = #wrkSchedule, [grpDescription] = #grpDescription WHERE [grpID] = #grpID">
<DeleteParameters>
<asp:Parameter Name="grpID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter DbType="DateTime" Name="grpStartTime" />
<asp:Parameter DbType="DateTime" Name="grpEndTime" />
<asp:Parameter Name="wrkSchedule" Type="String" />
<asp:Parameter Name="grpDescription" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter DbType="DateTime" Name="grpStartTime" />
<asp:Parameter DbType="DateTime" Name="grpEndTime" />
<asp:Parameter Name="wrkSchedule" Type="String" />
<asp:Parameter Name="grpDescription" Type="String" />
<asp:Parameter Name="grpID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:EmployeeMGTConnectionString %>" SelectCommand="SELECT [wrkCode], [wrkDescription], [wrkID] FROM [wrkSchedule]"></asp:SqlDataSource>
If I run it with this code for the dropdown list:
<asp:DropDownList ID="drpWrkSchedule" runat="server" DataSourceID="SqlDataSource2" DataTextField="wrkDescription" DataValueField="wrkCode" SelectedValue='<%#Bind("wrkCode")%>'>
I get the error. IF I run it without the "SelectedValue='<%#Bind("wrkCode")%>'" code, it presents the dropdown list as I need, just without a selected value that connects to the data from the data currently in the table.
I've looked at several examples from all over the web and it may be that I'm just missing something small. I just can't figure this out.
Thanks!
You need to select the wrkCode in your sqldatasource1 otherwise it has nothing to bind to. So just include wrkCode in your select clause of that sql statement and you should be good to go.

Can you please tell me why I am getting `The GridView 'GridView1' fired event RowUpdating which wasn't handled.` error message

I have been able to work through the initial problem of not being able to insert records consistently but a new error message crops up.
Now, I am getting The GridView 'GridView1' fired event RowUpdating which wasn't handled.
This error occurs when I click the Update button to update a row of record.
First, I click Edit button. This exposes the Update/Cancel buttons.
When I click the Update button, I get the aforementioned error.
My first take was that gridview needed onRowUpdating but after adding (see markup code), still getting same error.
This is a bit frustrating.
Here is the code.
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim dd As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlstatus"), DropDownList)
e.NewValues("status") = dd.SelectedItem.Text
End Sub
Markup:
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False" DataKeyNames="reqnum" AllowPaging="True"
CellPadding="4" ForeColor="#333333" GridLines="None" Visible="True"
OnRowDataBound="gvRowDataBound" OnRowEditing="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
EnableViewState="False" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="rownum" HeaderText="rownum" InsertVisible="False" ReadOnly="True"
SortExpression="rownum" />
<asp:BoundField DataField="reqnum" HeaderText="reqnum" SortExpression="reqnum" />
<asp:BoundField DataField="reqrecdate" HeaderText="reqrecdate" SortExpression="reqrecdate" />
<asp:BoundField DataField="reqrecfrom" HeaderText="reqrecfrom" SortExpression="reqrecfrom" />
<asp:BoundField DataField="skillsets" HeaderText="skillsets" SortExpression="skillsets" />
<asp:BoundField DataField="application" HeaderText="application" SortExpression="application" />
<asp:BoundField DataField="hoursperweek" HeaderText="hoursperweek" SortExpression="hoursperweek" />
<asp:BoundField DataField="fromdate" HeaderText="fromdate" SortExpression="fromdate" />
<asp:BoundField DataField="todate" HeaderText="todate" SortExpression="todate" />
<%-- <asp:BoundField DataField="status" HeaderText="status" SortExpression="status" />--%>
<asp:TemplateField HeaderText="status">
<EditItemTemplate>
<asp:DropDownList id="ddlstatus" CssClass="dropdown" DataSourceID="DSforDDL" runat="server">
<asp:ListItem Text="none" Value=""></asp:ListItem>
<asp:ListItem>Not Started</asp:ListItem>
<asp:ListItem>Pending</asp:ListItem>
<asp:ListItem>Completed</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblstatus" runat="server" Text='<% #Bind("status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="statusupdate" HeaderText="statusupdate" SortExpression="statusupdate" />
<asp:BoundField DataField="statusupby" HeaderText="statusupby" SortExpression="statusupby" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT Distinct [rownum],[reqnum], [reqrecdate], [reqrecfrom], [skillsets], [application], [hoursperweek], [fromdate], [todate], [status], [statusupdate], [statusupby] FROM [Term] ORDER BY [reqnum]"
UpdateCommand="INSERT INTO Term(reum, reqrecdate, reqrecfrom, skillsets, application, hoursperweek, fromdate, todate, status, statusupby, statusupdate) VALUES (#reum,#reqrecdatelbltxt, #reqrecfromlbltxt, #skillsets, #application, #hoursperweek,#fromdate,#todate, #status, #lognametxt, #logdatetxt)"
<DeleteParameters>
<asp:Parameter Name="rownum" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="reqnum" Type="String" />
<asp:Parameter DbType="DateTime" Name="reqrecdate" />
<asp:Parameter Name="reqrecfrom" Type="String" />
<asp:Parameter Name="skillsets" Type="String" />
<asp:Parameter Name="application" Type="String" />
<asp:Parameter Name="hoursperweek" Type="Int32" />
<asp:Parameter DbType="DateTime" Name="fromdate" />
<asp:Parameter DbType="DateTime" Name="todate" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter DbType="DateTime" Name="statusupdate" />
<asp:Parameter Name="statusupby" Type="String" />
<asp:Parameter Name="rownum" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
Thanks a lot in advance for your assistance.
The gridView tracks handlers to ensure something has been added to deal with the update intentionally.
Unless you are Manually calling "AddHandler" somewhwere else in code, I don't see a handles claus on your event method that would intercept the event being raised.

Radgrid edit/update not working

I'm having a wired problem with Radgrid.. Im using a Radgrid to display some results where the user can edit/update/delete them. I'm using a single SQL Server 2000 table to fetch the results... Not sure why the events are not firing in radgrid. But I am able to do it successfully using the Gridview control...
Im using .NET framework 4
Radgrid code
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteColumn="True"
AutoGenerateEditColumn="True" DataSourceID="SSDS" GridLines="None" Width="844px"
DataMember="DefaultView">
<MasterTableView DataSourceID="SSDS" DataKeyNames="id">
<Columns>
<telerik:GridBoundColumn DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id"
UniqueName="id" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="name" HeaderText="name" SortExpression="name"
UniqueName="name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="address" HeaderText="address" SortExpression="address"
UniqueName="address">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<br />
<br />
<asp:SqlDataSource ID="SSDS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringSQL %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringSQL.ProviderName %>" SelectCommand="SELECT [id], [name], [address] FROM [sitelinks]"
UpdateCommand="UPDATE [sitelinks] set [name] = ? , [address] = ? where [id] = ?"
DeleteCommand="delete from sitelinks where id = ?">
<DeleteParameters>
<asp:Parameter Name="id" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="name" />
<asp:Parameter Name="address" />
<asp:Parameter Name="id" />
</UpdateParameters>
</asp:SqlDataSource>
Gridview control code (the one that works)
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SSDS"
DataKeyNames="id">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" Visible="false" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SSDS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringSQL %>"
DeleteCommand="delete from sitelinks where id = ?" ProviderName="<%$ ConnectionStrings:ConnectionStringSQL.ProviderName %>"
SelectCommand="select id,name,address from sitelinks" UpdateCommand="update sitelinks set name=?, address=? where id = ? ">
<UpdateParameters>
<asp:ControlParameter ControlID="GridView1" Name="name" />
<asp:ControlParameter ControlID="GridView1" Name="address" />
<asp:ControlParameter ControlID="GridView1" Name="id" />
</UpdateParameters>
<DeleteParameters>
<asp:ControlParameter ControlID="GridView1" Name="id" />
</DeleteParameters>
</asp:SqlDataSource>
Thanks
Set the AllowAutomaticUpdates/AllowAutomaticDeletes properties of the telerik grid to true and see this sample.

dropdown list wont populate values from sql database

I've been strugglng with this one problem for a while now. I have an application as:
<asp:SqlDataSource runat="server" ID="categoriesDataSource"
SelectCommand="SELECT [CategoryID], [Name], [UserId] FROM [Categories] WHERE ([UserId] = #UserId) ORDER BY [Name]">
<SelectParameters>
<asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" />
</SelectParameters>
</asp:SqlDataSource>
Pick a category:
<asp:DropDownList ID="categories" runat="server" AutoPostBack="True"
DataSourceID="categoriesDataSource" DataTextField="Name"
DataValueField="CategoryID" AppendDataBoundItems="True">
<asp:ListItem Selected="True" Value="">-- All Categories --</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="picturesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT PictureID, Title, UploadedOn
FROM Pictures
WHERE UserId = #UserId AND
(CategoryID = #CategoryID OR #CategoryID IS NULL)
ORDER BY UploadedOn DESC" CancelSelectOnNullParameter="False">
<SelectParameters>
<asp:QueryStringParameter Name="UserId" QueryStringField="ID" />
<asp:ControlParameter ControlID="categories" Name="CategoryID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="PictureID" DataSourceID="picturesDataSource" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="PictureID"
DataNavigateUrlFormatString="~/Photodetail.aspx?ID={0}" Text="View Comments" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="UploadedOn" HeaderText="Date Added"
SortExpression="UploadedOn" />
<asp:ImageField DataImageUrlField="PictureID"
DataImageUrlFormatString="~/UploadedImages/{0}.jpg" HeaderText="Image">
<ControlStyle Width="100px" />
</asp:ImageField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
When i take away the
<SelectParameters>
<asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" />
</SelectParameters>
and ([UserId] = #UserId), the dropdown list control will populate values from the database but when I leave those 2, it won't populate any value from the database.
When I remove the
<asp:QueryStringParameter Name="CategoryID" QueryStringField="ID" />
</SelectParameters>,
and leave ([UserId] = #UserId), I get the error:
Must declare the scalar variable "#UserId".
Can somebody please help me out?
Thanks in advance
The one I posted here in your previous thread is definitely working.
I think you might have missed out the "ID" querystring in your url.
Are you browsing to "http://localhost:1234/WebAppName/PageName.aspx?=12"? (assume the auto generated port number is 1234 and the ID is 12)
It will throw error if you don't specify "?ID=12".
public void bind()
{
sqldataadapter da=new sqldataadapter("select A,B from table",cn);
datatable dt=new datatable();
da.fill(dt);
dropdownlist1.datatextfield="A";
dropdownlist1.datavaluefield="B";
dropdownlist1.datasource=dt;
dropdownlist1.databind();
}

Resources