i am making a website....in which i am retriving xml values from url..the xml values are retrived pefectly.affter bnding data from url to dropdownlist ..whenever i select any items in the dropdownlist ..ony the first item in the dropdown list is selected.......i have binding values from url to dropdownlist in the page load event.....please help me out..because of this dropdownlist problem..my whole project is not proceeding further.......my dropdownlsit contains different mobile service providers name like vodafhone.airtel,aircel...etc
below is my r_operatorcodes table..i am loading values from xml and binding values into table and hen into dropdownlist..
below is my filloperator method which is used to bind xml values into dropdownlist.
private void filloperator()
{
DataSet ds;
SqlDataAdapter da;
SqlConnection con;
ds = new DataSet();
con = new SqlConnection(@"Data Source=;Initial Catalog=;Integrated Security=True");
ds.ReadXml("http://letitgo.asia/api/serviceData.go?apimode=test&goid=5011000001&password=test123&rtype=xml&service_family=01");
SqlBulkCopy sbc = new SqlBulkCopy("Data Source=.;Initial Catalog=test;Integrated Security=True");
sbc.DestinationTableName = "r_operatorcodes";
con.Open();
sbc.WriteToServer(ds.Tables[0]);
DropDownList4.DataTextField = "operator_name";
DropDownList4.DataValueField = "operator_name";
DropDownList4.DataSource = ds;
DropDownList4.DataBind();
DropDownList4.Items.Insert(0, "-Select-");
}
below is my snapshot of the panel in which the drodownlist is there
below is my asp.page code
<asp:Panel ID="Panel4" runat="server" BorderColor="Black" BorderWidth="2px"
Width="296px">
<table style="width:100%;">
<tr>
<td class="style14">
Mobile Recharge</td>
<td class="style15">
</td>
</tr>
<tr>
<td class="style16">
Enter Transaction Details</td>
<td class="style15">
</td>
</tr>
<tr>
<td class="style16">
Enter Client_Trans_Id</td>
<td class="style15">
<asp:TextBox ID="TextBox23" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style16">
Enter Mobile No</td>
<td class="style15">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style16">
Select Operator</td>
<td class="style15">
<asp:DropDownList ID="DropDownList4" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style16">
Amount</td>
<td class="style15">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style13">
</td>
<td class="style15">
<table style="width:100%;">
<tr>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click1"
Text="Submit" />
</td>
<td>
<asp:Button ID="Button3" runat="server" onclick="Button3_Click1"
Text="Reset All" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Panel>
below is my the whole .cs page
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.Net;
using System.Data.SqlClient;
public partial class MASTERS_Recharge : System.Web.UI.Page
{
//masters2 ms2 = new masters2();
DataSet ds = new DataSet();
string mobile,amount,mclientid,dclientid;
masters3 ms = new masters3();
string op, opcode = "",dthcode;
string Airtel;
string username, password;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
filloperator();
filldthoperator();
}
private void filloperator()
{
DataSet ds;
SqlDataAdapter da;
SqlConnection con;
ds = new DataSet();
con = new SqlConnection(@"Data Source=;Initial Catalog=;Integrated Security=True");
ds.ReadXml("http://letitgo.asia/api/serviceData.go?apimode=test&goid=5011000001&password=test123&rtype=xml&service_family=01");
SqlBulkCopy sbc = new SqlBulkCopy("Data Source=.;Initial Catalog=test;Integrated Security=True");
sbc.DestinationTableName = "r_operatorcodes";
con.Open();
sbc.WriteToServer(ds.Tables[0]);
DropDownList4.DataTextField = "operator_name";
DropDownList4.DataValueField = "operator_name";
DropDownList4.DataSource = ds;
DropDownList4.DataBind();
DropDownList4.Items.Insert(0, "-Select-");
}
}
Below is my button click event on which i want dropdownlist values.
if (TextBox23.Text == "")
{
ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert('Enter Client trans id');", true);
}
mclientid = TextBox23.Text;
if (TextBox1.Text == "")
{
ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert('Enter mobile no');", true);
}
else
mobile = TextBox1.Text;
if (DropDownList4.SelectedIndex == -1)
{
ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert('select operator ');", true);
}
op = DropDownList4.SelectedItem.Text; /whenever i select any other value /i am always getting the zeroth index value in the dropdownlist
//ds = ms.selectcode(op);
//if (ds.Tables[0].Rows.Count > 0)
//{
// opcode = ds.Tables[0].Rows[0]["operator_code"].ToString();
//}
opcode = "28";
if (TextBox2.Text == "")
{
ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert('Enter amount');", true);
}
else
amount = TextBox2.Text;
SqlDataAdapter da;
ds = new DataSet();
SqlConnection con;
//ds = new DataSet();
con = new SqlConnection(@"Data Source=;Initial Catalog=;Integrated Security=True");
ds.ReadXml("http://letitgo.asia/api/serviceTrans.go?apimode=test&goid=5011000001&password=test123&rtype=xml&service_family=01&msisdn=" + TextBox1.Text + "&operator_code=" + opcode + "&amount=" + TextBox2.Text + "&client_transid=" + TextBox23.Text);
SqlBulkCopy sbc = new SqlBulkCopy("Data Source=.;Initial Catalog=test;Integrated Security=True");
sbc.DestinationTableName = "rounak";
con.Open();
sbc.WriteToServer(ds.Tables[0]);
//ds = ms.selectmtransaction(TextBox23.Text);
if (ds.Tables[0].Rows.Count > 0)
{
//some msg
}
con.Close();