Click here to Skip to main content
12,448,219 members (49,626 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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"  ) %>' >
***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.
Posted 16-Dec-12 19:53pm
Updated 16-Dec-12 20:10pm
v2
Comments
chathuranga333 17-Dec-12 4:53am
   
when you are trying to use the values of dropdownlist's. because its value is readable only in edit mode of the grid.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
m_safaaaa 19-Dec-12 2:24am
   
Still Not Working, cityid and branchid textboxes are treated as if they are empty
m_safaaaa 19-Dec-12 5:17am
   
But the value of the textbox cityid is binded : <telerik:RadTextBox ID="cityid" runat="server" Height="28px" Visible="true" Text='<%# DataBinder.Eval( Container, "DataItem.cityID" ) %>' > and in page load i can see the right values, but when i want to use it it is treated as if it is empty.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160811.3 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100