can u help me correcting the code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karodegaurav
    New Member
    • Apr 2010
    • 5

    can u help me correcting the code

    hi i m trying to connect the radiobutton list with the different view inside the multiview control. the first view is the bulletedlist second is the file upload and third is the url control. when i m running the following code the error "cannot implicitly convert type string to int"is coming.plz hep me solving this problem. my aspx code is

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default17.aspx.cs" Inherits="Default17" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
        <style type="text/css">
            #form1
            {
                height: 350px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div style="height: 0px">
        
        </div>
        
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" 
            onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" 
            RepeatDirection="Horizontal" DataSourceID="XmlDataSource2" 
            DataTextField="text" DataValueField="text">
            <asp:ListItem Value="0">bulletedlist</asp:ListItem>
            <asp:ListItem Value="1">fileupload</asp:ListItem>
            <asp:ListItem Value="2">htmlcode</asp:ListItem>
        </asp:RadioButtonList>
       
    
        <asp:MultiView ID="MultiView1" runat="server">
            <asp:View ID="View1" runat="server">
            <asp:BulletedList ID="BulletedList1" runat="server" 
            DataSourceID="XmlDataSource1" DataTextField="text" DataValueField="url" 
            Font-Bold="True" Height="20px" Width="130px" DisplayMode="HyperLink">
            <asp:ListItem>Microsoft</asp:ListItem>
            <asp:ListItem>Msdn</asp:ListItem>
            <asp:ListItem>asp.net</asp:ListItem>
        </asp:BulletedList>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml">
        </asp:XmlDataSource>
            
            </asp:View>
            <asp:View ID="View2" runat="server">
             <p>
            <asp:FileUpload ID="FileUpload1" runat="server" />
        </p>
        <p>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="upload" />
        </p>
        <asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>
            </asp:View>
            <asp:View ID="View3" runat="server">
            <a href="kasdjlkajdsadaldkaskfhafafffffffffff.htm">
        kasdjlkajdsadaldkaskfhafafffffffffff.htm</a>&nbsp;&nbsp;&nbsp;
        <a href = "good.htm">good.htm</a><br />
            </asp:View>
            
        </asp:MultiView>
    </form>
    </body>
    </html>
    and my cs code is as-


    Code:
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    
    
    
    public partial class Default17 : System.Web.UI.Page
    {
       
    
    
        protected void Page_Load(object sender, EventArgs e )
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                FileUpload1.SaveAs("C:\\Documents and Settings\\m.MM-4A6934257FDF\\My Documents\\Visual Studio 2008\\WebSites\\WebSite4\\uploadd" + FileUpload1.FileName);
                HyperLink1.Text = FileUpload1.FileName;
                HyperLink1.NavigateUrl = "uploadd" + FileUpload1.FileName;
                
            }
        }
        
        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
         
          MultiView1.ActiveViewIndex=RadioButtonList1.SelectedValue; 
        }
    }

    the last line of the code has the error "cannot implicitly convert type string to int"

    thank in advance
    _______________ _______________ _______________ _______________ _____
    Last edited by Frinavale; Apr 27 '10, 03:59 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    On the last line you have:
    MultiView1.Acti veViewIndex="Ra dioButtonList1. SelectedValue";

    Why do you have double quotes around RadioButtonList 1.SelectedValue ?

    The MultiView.Activ eViewIndex is expecting an Integer....and because you have double quotes around the RadioButtonList 1.SelectedValue you are supplying it with a string. This doesn't make sense to the compiler...and it doesn't make sense to me.

    It's pretty obvious that you need to remove the quotes......... ..

    Since the MultiView.Activ eViewIndex is expecting an integer you have to make sure that the SelectedValue contains a number...if it doesn't then you will see this error again.

    -Frinny

    Comment

    • karodegaurav
      New Member
      • Apr 2010
      • 5

      #3
      Originally posted by Frinavale
      On the last line you have:
      MultiView1.Acti veViewIndex="Ra dioButtonList1. SelectedValue";

      Why do you have double quotes around RadioButtonList 1.SelectedValue ?

      The MultiView.Activ eViewIndex is expecting an Integer....and because you have double quotes around the RadioButtonList 1.SelectedValue you are supplying it with a string. This doesn't make sense to the compiler...and it doesn't make sense to me.

      It's pretty obvious that you need to remove the quotes......... ..

      Since the MultiView.Activ eViewIndex is expecting an integer you have to make sure that the SelectedValue contains a number...if it doesn't then you will see this error again.

      -Frinny
      hi Frinavale ,
      Thank you very much for ur reply. i tried to use ur given suggestion but the problem is still there. it is still showing the same error. I ve taken the values of radiobuttonlist 1 as 0,1,2. plz have a look again to the code and plz reply
      thank you

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Use the Visual Studio to step through the area that you are having problems with.
        Check to make sure that you are supplying an Integer value where it is expected...if you are supplying a String, and the string contains a number, you need to convert the string into an integer (using the Integer.Parse() method)

        Comment

        Working...