在gridview中的Sqldatasource [英] Sqldatasource inside gridview
问题描述
或过去几天我一直在努力为我的问题找到解决方案,但到目前为止我还不能。我有一个Gridview,在编辑模式下,其中一个字段有一个DropDownList,由一个Select填充,使用该行的另外两个字段(State和City)。我尝试了我在网上找到的关于它的一切,但我无法使它工作。你能帮我吗?代码如下
or the past days i've been trying to find a solution for my problem but so far i couldn't. I Have a Gridview that in edit mode, one of the fields have a DropDownList of people that is populated by a Select that uses two other fields of that row (State and City). I tried everything i found on the web about it and i couldn't make it work. Can you help me please? Code below
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
DataKeyNames="id,Municipio,UF" DataSourceID="SqlDataSource5">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
...stuff...
<asp:TemplateField HeaderText="UF" SortExpression="UF">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("UF") %>'>
</asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("UF") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Municipio" SortExpression="Municipio">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Municipio") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Municipio") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="People" SortExpression="People">
<ItemTemplate>
<asp:Label ID="LbPeople" runat="server" Text='<%# Bind("Cultura") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DdlPeople" runat="server" AutoPostBack="true"
DataSourceID="SqlDataSourcePeopleEdit" DataTextField="People"
DataValueField="People">
</asp:DropDownList>
<asp:HiddenField ID="Hidden1" Value='<%# Bind("Municipio") %>' runat="server"/>
<asp:HiddenField ID="Hidden2" Value='<%# Bind("UF") %>' runat="server"/>
<asp:SqlDataSource ID="SqlDataSourcePeopleEdit" runat="server"
ConnectionString="<%$ ConnectionStrings:dbdb %>"
ProviderName="<%$ ConnectionStrings:somar.ProviderName %>"
SelectCommand="SELECT People FROM Table_People WHERE (Cidade = @Municipio) AND (UF = @UF)"
CancelSelectOnNullParameter="false">
<SelectParameters>
<asp:ControlParameter ControlID="Hidden1" Name="Municipio" PropertyName="Value" Type="String" />
<asp:ControlParameter ControlID="Hidden2" Name="UF" PropertyName="Value" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
</asp:TemplateField>
...stuff...
</asp:GridView>
什么我做错了吗?
我尝试了什么:
什么时候我点击编辑,下拉列表不加载值。如果我在SqlDataSource上设置属性CancelSelectOnNullParameter =false它显示'必须声明标量变量@xxx'我已经检查了隐藏字段并且它们已经加载了值,所以问题是控制参数taht没有从中获取值
What am i doing wrong?
What I have tried:
When i click edit, the dropdownlist does not load values. And if i set the property CancelSelectOnNullParameter="false" on SqlDataSource it shows 'Must declare scalar variable @xxx' I have inspected the hiddenfields and they have values loaded, so the problem is the controlparameter taht does not get the value from it
推荐答案
ConnectionStrings:dbdb%>
ProviderName = <%
ConnectionStrings:dbdb %>" ProviderName="<%
ConnectionStrings:somar.ProviderName%>
< span class =code-attribute> SelectCommand = SELECT FROM FROM Table_People WHERE(Cidade = @Municipio)AND(UF = @UF)
< span class =code-attribute>
CancelSelectOnNullParameter = false > / >
< SelectParameters >
< asp:ControlParameter ControlID = Hidden1 名称 = Municipio PropertyName = 值 类型 = 字符串 / >
< asp:ControlParameter ControlID = Hidden2 名称 = UF < span class =code-attribute> PropertyName = 值 类型 = 字符串
< / SelectParameters >
< ; / asp:SqlDataSource >
< / EditItemTemplate >
< / asp:TemplateField >
。 ..stuff ...
< / asp:GridView >
ConnectionStrings:somar.ProviderName %>" SelectCommand="SELECT People FROM Table_People WHERE (Cidade = @Municipio) AND (UF = @UF)" CancelSelectOnNullParameter="false"> <SelectParameters> <asp:ControlParameter ControlID="Hidden1" Name="Municipio" PropertyName="Value" Type="String" /> <asp:ControlParameter ControlID="Hidden2" Name="UF" PropertyName="Value" Type="String" /> </SelectParameters> </asp:SqlDataSource> </EditItemTemplate> </asp:TemplateField> ...stuff... </asp:GridView>
我做错了什么?
我尝试过:
W如果我点击编辑,下拉列表不会加载值。 And if i set the property CancelSelectOnNullParameter=\"false\" on SqlDataSource it shows ’Must declare scalar variable @xxx’ I have inspected the hiddenfields and they have values loaded, so the problem is the controlparameter taht does not get the value from it
What am i doing wrong?
What I have tried:
When i click edit, the dropdownlist does not load values. And if i set the property CancelSelectOnNullParameter="false" on SqlDataSource it shows 'Must declare scalar variable @xxx' I have inspected the hiddenfields and they have values loaded, so the problem is the controlparameter taht does not get the value from it
这篇关于在gridview中的Sqldatasource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!