Click here to Skip to main content
Rate this: bad
good
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"  ) %>' >
            </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:
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
Edited 16-Dec-12 20:10pm
v2
Comments
chathuranga333 at 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 at 19-Dec-12 2:24am
   
Still Not Working, cityid and branchid textboxes are treated as if they are empty
m_safaaaa at 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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 397
1 OriginalGriff 380
2 Shai Vashdi 280
3 Emre Ataseven 135
4 Abhinav S 128
0 Sergey Alexandrovich Kryukov 8,894
1 OriginalGriff 5,200
2 Peter Leow 3,955
3 Maciej Los 3,535
4 Abhinav S 3,208


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid