无法显示下拉列表的正确值 [英] cannot display the right value of a dropdownlist

查看:71
本文介绍了无法显示下拉列表的正确值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我的网格包含3个字段:CityID,BranchID和Edit链接。



当我点击编辑链接时,会显示一个带有正确编辑项目的Web用户控制页面addFacilty.ascx。



addFacilty.ascx包括2个下拉列表ddlCity和ddlBranch以及2个文本框cityid和branchid



我希望下拉列表包含结果:



1-ddlcity:具有id的城市:cityid.text.tostring()

2-ddlbranch:具有id的分支:branchid.text.tostring();



请注意,cityid和branchid是两个文本框,Text值绑定到grid。所以它是自动填充的。



我现在的问题是当我点击网格的编辑链接时。 webUser控制页面的cityid和branchid显示正确的项目。但是当我想使用它们的值时,cityid和branchid被视为空的。



下面是addFacilty.ascx的代码:

Hello,

I have a grid that contains 3 fields: CityID, BranchID and Edit link.

When i click on the edit link, a web user control page "addFacilty.ascx" is displayed with the right edited items.

"addFacilty.ascx" include 2 dropdown lists ddlCity and ddlBranch and 2 textboxes cityid and branchid

I want that the dropdownlists contain as result:

1-ddlcity: the city having id: cityid.text.tostring()
2-ddlbranch: the branch having id : branchid.text.tostring();

Note that cityid and branchid are two textboxes with Text value is bind to grid. so it is automaically filled.

My problem now is that when i click on edit link of the grid. cityid and branchid of the webUser control page displays the right item. but when i want to use their values, cityid and branchid are treated as if they are empty.

below is the code of "addFacilty.ascx":

 <asp:DropDownList ID="ddlCity" runat="server" DataSourceID="tblCity" DataTextField="city" DataValueField="cityID" AutoPostBack="true" SelectedValueField='<%#DataBinder.Eval( Container, "DataItem.cityID") %>'>
            </asp:DropDownList>
            <asp:SqlDataSource ID="tblCity" runat="server" ConnectionString="<% $ ConnectionStrings:SmartBookingEngineConn %>" SelectCommand="select cityID,city from viewCityAdmin"></asp:SqlDataSource>
        
<asp:DropDownList ID="ddlBranch" runat="server" DataSourceID="tblBranch"

                DataTextField="Branch" DataValueField="BranchID">
           
            </asp:DropDownList>

            <asp:SqlDataSource ID="tblBranch" runat="server" ConnectionString="<%$ ConnectionStrings:SmartBookingEngineConn %>" SelectCommand="SELECT [BranchID],[Branch] FROM [tblBranch] WHERE ([CityID]=@cityID)">
               <SelectParameters>
                <asp:ControlParameter Name="cityID" ControlID="ddlCity" PropertyName="SelectedValue" Type="String" />
               </SelectParameters>
            </asp:SqlDataSource> 

<telerik:RadTextBox ID="cityid"  runat="server" Height="28px" Visible="true"  Text='<%# DataBinder.Eval( Container, "DataItem.cityID"  ) %>' >
            </telerik:RadTextBox>

 <telerik:RadTextBox ID="branchid"  runat="server" Height="28px" Visible="true" Text='<%# DataBinder.Eval( Container, "DataItem.BranchID")%>' AutoPostBack="true">
            </telerik:RadTextBox>



*** addFacilty.ascx.cs:


***addFacilty.ascx.cs:

protected void Page_Load(object sender, EventArgs e)
{
if (cityid.Text.ToString() != "" && branchid.Text.ToString() !=""){                      
string selectedIDCity = cityid.Text.ToString();
tblCity.SelectCommand = "Select * from viewCityAdmin where cityID=@cityid";
tblCity.SelectParameters.Clear();
tblCity.SelectParameters.Add("cityid", selectedIDCity);
tblCity.DataBind();

string selectedIDBranch = branchid.Text.ToString();
tblBranch.SelectCommand = "Select * from tblBranch where BranchID=@branchid";
tblBranch.SelectParameters.Clear();
tblBranch.SelectParameters.Add("branchid", selectedIDBranch);
tblBranch.DataBind();
}
}





提前谢谢。



thank you in advance.

推荐答案

ConnectionStrings:SmartBookingEngineConn%> SelectCommand = 从viewCityAdmin选择cityID,city > < / asp:SqlDataSource >

< asp:DropDownList ID = ddlBranch runat = server DataSourceID = tblBranch

DataTextField = 分支 DataVa lueField = BranchID >

< / asp:DropDownList >

< asp:SqlDataSource ID = tblBranch runat = server ConnectionString = <%
ConnectionStrings:SmartBookingEngineConn %>" SelectCommand="select cityID,city from viewCityAdmin"></asp:SqlDataSource> <asp:DropDownList ID="ddlBranch" runat="server" DataSourceID="tblBranch" DataTextField="Branch" DataValueField="BranchID"> </asp:DropDownList> <asp:SqlDataSource ID="tblBranch" runat="server" ConnectionString="<%


ConnectionStrings:SmartBookingEngineConn%&g t; SelectCommand = SELECT [BranchID],[Branch] FROM [tblBranch] WHERE([CityID] = @ cityID) >
< SelectParameters > ;
< asp:ControlParameter 名称 = cityID ControlID = ddlCity PropertyName = SelectedValue 类型 = 字符串 / < span class =code-keyword>>
< / SelectParameters >
< / asp: SqlDataSource >

< telerik:RadTextBox ID = cityid runat = server 高度 = 28px < span class =code-attribute>可见 = true 文字 = ' <%#DataBinder.Eval(Container, DataItem.cityID)%>' >
< / telerik:RadTextBox < span class =code-keyword>>

< telerik:RadTextBox ID = branchid runat = server 高度 = 28px 可见 = true 文字 =' <%#DataBinder.Eval( Container, DataItem.BranchID)%>' AutoPostBack = true >
< / telerik:RadTextBox >
ConnectionStrings:SmartBookingEngineConn %>" SelectCommand="SELECT [BranchID],[Branch] FROM [tblBranch] WHERE ([CityID]=@cityID)"> <SelectParameters> <asp:ControlParameter Name="cityID" ControlID="ddlCity" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:SqlDataSource> <telerik:RadTextBox ID="cityid" runat="server" Height="28px" Visible="true" Text='<%# DataBinder.Eval( Container, "DataItem.cityID" ) %>' > </telerik:RadTextBox> <telerik:RadTextBox ID="branchid" runat="server" Height="28px" Visible="true" Text='<%# DataBinder.Eval( Container, "DataItem.BranchID")%>' AutoPostBack="true"> </telerik:RadTextBox>

< br $>
*** addFacilty.ascx.cs:


***addFacilty.ascx.cs:

protected void Page_Load(object sender, EventArgs e)
{
if (cityid.Text.ToString() != "" && branchid.Text.ToString() !=""){                      
string selectedIDCity = cityid.Text.ToString();
tblCity.SelectCommand = "Select * from viewCityAdmin where cityID=@cityid";
tblCity.SelectParameters.Clear();
tblCity.SelectParameters.Add("cityid", selectedIDCity);
tblCity.DataBind();

string selectedIDBranch = branchid.Text.ToString();
tblBranch.SelectCommand = "Select * from tblBranch where BranchID=@branchid";
tblBranch.SelectParameters.Clear();
tblBranch.SelectParameters.Add("branchid", selectedIDBranch);
tblBranch.DataBind();
}
}





提前谢谢。



thank you in advance.


hi ,



将您的代码更改为...





Change your code to ...

protected void Page_Load(object sender, EventArgs e)
{
if (cityid.Text.ToString() != "" && branchid.Text.ToString() !=""){
string selectedIDCity = cityid.Text.ToString();
tblCity.SelectCommand = "Select * from viewCityAdmin where cityID="+ selectedIDCity ;
tblCity.SelectParameters.Clear();
tblCity.SelectParameters.Add("cityid", selectedIDCity);
tblCity.DataBind();

string selectedIDBranch = branchid.Text.ToString();
tblBranch.SelectCommand = "Select * from tblBranch where BranchID="+ selectedIDBranch ;
tblBranch.SelectParameters.Clear();
tblBranch.SelectParameters.Add("branchid", selectedIDBranch);
tblBranch.DataBind();
}
}





这可能有用。

试一试。



谢谢



This may work.
Try this out.

Thanks


这篇关于无法显示下拉列表的正确值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆