Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.NET
 <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:
C#
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
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

hi,

Change your code to ...

C#
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
 
Share this answer
 
Comments
m_safaaaa 19-Dec-12 2:24am    
Still Not Working, cityid and branchid textboxes are treated as if they are empty
[no name] 19-Dec-12 2:57am    
Yes you won't get the values as you are trying to retrieve the value on page load. During page load your text box value are not been containing any values. Pass the cityID and BranchId on link button click and assign that valus on page load.Then you can able to achieve your goal.
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900