How to add additional text from other tables in drop down list [Resolved]

Posted by Pkanwar under ASP.NET on 3/9/2013 | Points: 10 | Views : 1145 | Status : [Member] | Replies : 3
Hi ,
We have a country table, which have country code and country name, these country names have been shown in drop down list. Now We have added another table, which have same country code and another country name:

For example: 1 Table have Countrycode: 1, CountryName: India - It has been shown in DropDown List:
2. Table have same country Code:1, CountryName: Indian:

OutPut is: In drop- down list: should be shown: India and Indian also, If we enter name in second table.



Thanks




Responses

Posted by: Satyapriyanayak on: 3/9/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm8.aspx.cs" Inherits="WebApplication16.WebForm8" %>

<!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>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</form>
</body>
</html>


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;
using System.Data.SqlClient;
namespace WebApplication16
{
public partial class WebForm8 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
b1();
b2();
}
}
void b1()
{
SqlConnection con = new SqlConnection(strConnString);
DropDownList1.Items.Add("Choose");
con.Open();
str = "select CountryName from t1 ";
com = new SqlCommand(str, con);
SqlDataReader reader1 = com.ExecuteReader();
while (reader1.Read())
{
DropDownList1.Items.Add(reader1["CountryName"].ToString());
}
reader1.Close();
con.Close();
}
void b2()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select CountryName from t2";
com = new SqlCommand(str, con);
SqlDataReader reader2 = com.ExecuteReader();
while (reader2.Read())
{
DropDownList1.Items.Add(reader2["CountryName"].ToString());
}
reader2.Close();
con.Close();
}
}
}


If this post helps you mark it as answer
Thanks

Pkanwar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pkanwar on: 3/9/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks, This code is very Helpful...
Keep it up :)..
Happy Coding...

Pkanwar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pkanwar on: 3/9/2013 [Member] Starter | Points: 25

Up
0
Down
Here I have added ListViewControll, But when I read data in ListView Controll. error shows have some invalid arguments. Please let me aware, where I am going to wrong.

try
{
SqlConnection con = new SqlConnection();
con.ConnectionString = CountryInfoProvider.StudentConnect;
con.Open();
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection = con;
sqlcmd.CommandText = "countryNew";
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.AddWithValue("@language", language.ToString());
SqlDataReader reader1 = sqlcmd.ExecuteReader();
while (reader1.Read())
{
dlvCountry.Items.Add(reader1["CountryName"].ToString()); This line error shows: have some invalid argument
}
reader1.Close();
con.Close();
}
catch (Exception)
{
throw;
}

Thanks

Pkanwar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response