我有一个看起来像这样的网格,它有DropDownlist1来填充数据,如下所示。 点击按钮时,下拉列表中的更新值存储到数据库中,这很好。 我想在页面上加载仅从下拉列表中存储的值,以在加载下拉列表中选择该特定值。我该怎么做? 所以它必须加载初始数据但是对于那些存储到DB的记录,它应该加载用户选择的内容吗? 你怎么能以任何方式将值从代码隐藏传递到网格中的下拉列表?
< pre lang = xml > < asp:GridView ID = GridView1 宽度 = 100% runat = server AutoGenerateColumns = 假 CellPadding = 4 DataKeyNames = client_id DataSourceID = SqlDataSource1 字体大小 = 中 Fore颜色 = #333333 GridLines = 无 AllowPaging = True AllowSorting = True > < AlternatingRowStyle BackColor = 白色 ForeColor = #284775 / > < 列 > < asp:BoundField DataField = client_id HeaderText = 客户端# InsertVisible = 错误 ReadOnly = True SortExpression = client_id / > < asp:BoundField DataField = name_first HeaderText = 名称 SortExpression = name_first / > < asp:BoundField DataField = name_last HeaderText = 姓 SortExpression = name_last / > < asp:BoundField 数据字段 = phone1 HeaderText = 电话号码 SortExpression = phone1 / > < asp:BoundField DataField = adress_line1 HeaderText = 地址 SortExpression = adress_line1 / > < asp:TemplateField HeaderText = 辅导员选择 > < ItemTemplate > < asp:DropDownList ID = DropDownList1 宽度 = 100% runat = server DataSourceID = SqlDataSource2 DataTextField = user_name DataValueField = user_name AppendDataBoundItems = true AutoPostBack = True > < asp:ListItem Text = - 选择 - 值 = > < / asp:ListItem > < / asp:DropDownList > < asp:SqlDataSource ID = SqlDataSource2 runat = server ConnectionString = <% $ ConnectionStrings:ocean4d_devConnectionString%> SelectCommand = SELECT [user_name] FROM [AgencyUser] WHERE([agency_id] = @agency_id) > < SelectParameters > < asp:SessionParameter 名称 = agency_id SessionField = agency_id 类型 = Int32 / > < / SelectPar ameter > < / asp:SqlDataSource > < / ItemTemplate > < / asp:TemplateField > < ASP:HYPERLINKFIELD text = & nbsp; UPDATE datanavigateurlfields = client_id datanavigateurlformatstring = main_page_process.aspx?client_id = {0} > < / ASP:HYPERLINKFIELD > < /列 > < EditRowStyle BackColor = #999999 / > & lt; FooterStyle BackColor = #5D7B9D Font-Bold = True ForeColor = 白色 / > < HeaderStyle BackColor = #5D7B9D Font-Bold = 真 ForeColor = 白色 / > < PagerStyle BackColor = #284775 ForeColor = 白色 HorizontalAlign = 中心 / > < RowStyle BackColor = #F7F6F3 ForeColor = #333333 / > < SelectedRowStyle BackColor = #E2DED6 字体粗体 = True ForeColor = #333333 / > < SortedAscendingCellStyle BackColor = #E9E7E2 / > < SortedAscendingHeaderStyle BackColor = #506C8C / > < SortedDescendingCellStyle BackColor = #FFFDF8 / > < SortedDescendingHeaderStyle BackColor = #6F8DAE / > < / asp:GridView > < asp:SqlDataSource ID = SqlDataSource1 runat = server ConnectionString = <% $ ConnectionStrings:ocean4d_devConnectionString%> SelectCommand = SELECT [client_id],[name_first],[name_last],[phone1],[adress_line1] FROM [客户] WHERE([agency_id] = @agency_id) > < SelectParameters > < asp:SessionParameter 名称 = agency_id SessionField = agency_id 类型 = 字符串 / > < / SelectParameters > < / asp:SqlDataSource >解决方案
ConnectionStrings:ocean4d_devConnectionString%> SelectCommand = SELECT [user_name] FROM [AgencyUser] WHERE([agency_id] = @agency_id) > < SelectParameters > < asp:SessionParameter 名称 = agency_id SessionField = agency_id 类型 = Int32 / > < / SelectParameters > < / asp:SqlDataSource > < / ItemTemplate > < / asp:TemplateField > < ASP:HYPERLINKFIELD text = & nbsp; UPDATE datanavigateurlfields = client_id datanavigateurlformatstring = main_page_process.aspx?client_id = {0} > < / ASP:HYPERLINKFIELD > < /列 > < ; EditRowStyle BackColor = #999999 / > < FooterStyle BackColor = #5D7B9D 字体 - 粗体 = 真 ForeColor = 白色 / > < HeaderStyle BackColor = #5D7B9D Font-Bold = True ForeColor = 白色 / > < PagerStyle BackColor = #284775 ForeColor = 白色 HorizontalAlign = 中心 / > < RowStyle BackColor = #F7F6F3 ForeColor = #333333 / > < SelectedRowStyle BackColor = #E2DED6 字体粗体 = True ForeColor = #333333 / > < SortedAscendingCellStyle BackColor = #E9E7E2 / > < SortedAscendingHeaderStyle BackColor = #506C8C / > < SortedDescendingCellStyle Ba ckColor = #FFFDF8 / > < SortedDescendingHeaderStyle BackColor = #6F8DAE / > < / asp:GridView > < asp:SqlDataSource ID = SqlDataSource1 runat = 服务器 ConnectionString = <% ConnectionStrings:ocean4d_devConnectionString %>\" SelectCommand=\"SELECT [client_id], [name_first], [name_last], [phone1], [adress_line1] FROM [Client] WHERE ( [agency_id] = @agency_id)\"> <SelectParameters> <asp:SessionParameter Name=\"agency_id\" SessionField=\"agency_id\" Type=\"String\" /> </SelectParameters> </asp:SqlDataSource>If you want to populate the dropdown from database, then you can use the dataset, populate the data from table into dataset and use a method to populate the dropdown using the dataset.
I have a grid that looks like this and it has DropDownlist1 that populates data as seen here. When clicked on a button Update value from dropdownlist is stored to DB and thats fine. I want on a page load only for those values stored from dropdown list to select that particular value in dropdown list on load. How can I do that? So it has to load initial data but for those records stored to DB it should load what user selected? How can you in any way pass the value from codebehind to dropdownlist in the grid?
<pre lang="xml"><asp:GridView ID="GridView1" Width="100%" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="client_id" DataSourceID="SqlDataSource1" Font-Size="Medium" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:BoundField DataField="client_id" HeaderText="Client #" InsertVisible="False" ReadOnly="True" SortExpression="client_id" /> <asp:BoundField DataField="name_first" HeaderText="Name" SortExpression="name_first" /> <asp:BoundField DataField="name_last" HeaderText="Surname" SortExpression="name_last" /> <asp:BoundField DataField="phone1" HeaderText="Phone #" SortExpression="phone1" /> <asp:BoundField DataField="adress_line1" HeaderText="Address" SortExpression="adress_line1" /> <asp:TemplateField HeaderText="Counselors Selection"> <ItemTemplate> <asp:DropDownList ID="DropDownList1" Width="100%" runat="server" DataSourceID="SqlDataSource2" DataTextField="user_name" DataValueField="user_name" AppendDataBoundItems="true" AutoPostBack="True"> <asp:ListItem Text="--Select--" Value=""></asp:ListItem> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ocean4d_devConnectionString %>" SelectCommand="SELECT [user_name] FROM [AgencyUser] WHERE ([agency_id] = @agency_id)"> <SelectParameters> <asp:SessionParameter Name="agency_id" SessionField="agency_id" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> </ItemTemplate> </asp:TemplateField> <ASP:HYPERLINKFIELD text=" UPDATE" datanavigateurlfields="client_id" datanavigateurlformatstring="main_page_process.aspx?client_id={0}"></ASP:HYPERLINKFIELD> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ocean4d_devConnectionString %>" SelectCommand="SELECT [client_id], [name_first], [name_last], [phone1], [adress_line1] FROM [Client] WHERE ([agency_id] = @agency_id)"> <SelectParameters> <asp:SessionParameter Name="agency_id" SessionField="agency_id" Type="String" /> </SelectParameters> </asp:SqlDataSource> 解决方案 ConnectionStrings:ocean4d_devConnectionString %>" SelectCommand="SELECT [user_name] FROM [AgencyUser] WHERE ([agency_id] = @agency_id)"> <SelectParameters> <asp:SessionParameter Name="agency_id" SessionField="agency_id" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> </ItemTemplate> </asp:TemplateField> <ASP:HYPERLINKFIELD text=" UPDATE" datanavigateurlfields="client_id" datanavigateurlformatstring="main_page_process.aspx?client_id={0}"></ASP:HYPERLINKFIELD> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%ConnectionStrings:ocean4d_devConnectionString %>" SelectCommand="SELECT [client_id], [name_first], [name_last], [phone1], [adress_line1] FROM [Client] WHERE ([agency_id] = @agency_id)"> <SelectParameters> <asp:SessionParameter Name="agency_id" SessionField="agency_id" Type="String" /> </SelectParameters> </asp:SqlDataSource>If you want to populate the dropdown from database, then you can use the dataset, populate the data from table into dataset and use a method to populate the dropdown using the dataset.更多推荐
如何将值传递给Grid中的DropDownList
发布评论