not getting text box when i click edit in gridview - c#

Code is not working When I click edit it is not showing any text box
protected void gdvDeptDetails_RowEditing(object sender, GridViewEditEventArgs e)
{
gdvDeptDetails.EditIndex = e.NewEditIndex;
BindData();
}
public void BindData()
{
con.Open();
da = new SqlDataAdapter("select * from deptinfo",con);
ds = new DataSet();
da.Fill(ds);
gdvDeptDetails.DataSource = ds;
gdvDeptDetails.DataBind();
}

'>
Convert your grid view fields in templates and give a text box in EditItemTemplate.

Related

Datagrid not showing

My data grid is not showing up in my webpage at all.As in no table showing up.
I did follow this stack question and modified some of its code to suit mine,but it's not showing at all.
here is the code for my class which is triggered by the button.
private void LoadDataGrid()
{
con.Open();
cmd = new SqlCommand(#"SELECT quotationID,quo_product
FROM JobQuotations
WHERE quo_custname = #custname", con);
cmd.Parameters.AddWithValue("#custname",lblLoginName.Text);
da = new SqlDataAdapter(cmd);
dt = new DataTable();
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
and I have inserted it inside the page_load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadDataGrid();
}
}
here is the markup:
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
You are missing da.Fill(dt);:
dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;

How to populate dependant dropdowns in Asp.Net C#

I want to populate TWO dropdownlist, based on selection of first dropdownlist the second dropdownlist will get populated.
Example :
Like i have two dropdownlist namely 1.ddlCountry and 2.ddlState
Now when country is selected then depending on the selected Country the States related with that Country will get populated in the State dropdownlist. I want to achieve this withour reloading the whole page in Asp.Net with coding language as C#.
How can i achieve the same?
Dropdownlist is fetching data from database by executing query.
You can use AJAX toolkit CascadingDropDown as told by Naresh.
OR
use ajax update panel and keep all Dropdowns in it. So the whole page will not load on changing dropdown value.
You didnt give the code to further solution.
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
FillStateByCountry();
}
protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
{
FillLocationByCountryandState();
}
private void FillStateByCountry()
{
DataSet dstFillState;
int CountryId = Convert.ToInt32(ddlCountry.SelectedValue.ToString());
dstFillState = Tbl_State.FillDDLState(CountryId);
ddlState.DataSource = dstFillState;
ddlState.DataTextField = "State";
ddlState.DataValueField = "Id";
ddlState.DataBind();
}
similarly FillLocationByCountryandState();
Add two dropdownlists to your form and name it as cmbStates, cmbCities
when you select state name from cmbStates(dropwdownlist), cmbCities(dropdownlist) generates cities based on state name(cmbStates)
by fetching data from database
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=pbs-server;database=p2p;user id=shekar;password=sekhar#1346");
SqlCommand cmd = new SqlCommand("select states from Country", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
da.Fill(ds, "Country");
cmbStates.DataSource = ds.Tables[0];
cmbStates.SelectedValue = 0;
con.Close();
}
private void cmbStates_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=xxxx;database=xxxx;user id=xxxxr;password=xxxxxx");
SqlCommand cmd = new SqlCommand("select cities from States where cityname = 'cmbStates.SelectedItem.ToString()'", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
da.Fill(ds, "States");
cmbCities.DataSource = ds.Tables[0];
cmbCities.SelectedValue = 0;
con.Close();
}
OR
manually adding items
namespace DropDownlist
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cmbStates.Items.Add("Andhra Pradesh");
cmbStates.Items.Add("Tamilnadu");
cmbStates.Items.Add("Karnataka");
cmbStates.SelectedValue = 0;
}
private void cmbStates_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbStates.SelectedItem.ToString() == "Andhra Pradesh")
{
cmbCities.Items.Clear();
cmbCities.Items.Add("Hyderabad");
cmbCities.Items.Add("Guntur");
cmbCities.Items.Add("Vijayawada");
cmbCities.SelectedValue = 0;
}
else if (cmbStates.SelectedItem.ToString() == "Tamilnadu")
{
cmbCities.Items.Clear();
cmbCities.Items.Add("Chennai");
cmbCities.Items.Add("Coimbatore");
cmbCities.Items.Add("ooty");
cmbCities.SelectedValue = 0;
}
else if (cmbStates.SelectedItem.ToString() == "Karnataka")
{
cmbCities.Items.Clear();
cmbCities.Items.Add("Bangalore");
cmbCities.Items.Add("Mangalore");
cmbCities.SelectedValue = 0;
}
else
{
MessageBox.Show("Please Select any value");
}
}
}
}

"System.Data.DataRowView" in form load using combobox in C#

Every time my forms loads/open it will prompt "System.Data.DataRowView", How can I possibly remove this?
Here is my code:
{
InitializeComponent();
GetProcessorCardTypes();
}
private void GetProcessorCardTypes()
{
cn.Open();
MySqlCommand cmd = new MySqlCommand("call GetProcessorMethod(1)", cn);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
cmbProcessorMethods.DataSource = dt;
cmbProcessorMethods.ValueMember = "method_id";
cmbProcessorMethods.DisplayMember = "method_name";
}
private void cmbProcessorMethods_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(cmbProcessorMethods.SelectedValue.ToString());
}
If you want to completely remove message box, then remove cmbProcessorMethods_SelectedIndexChanged event handler. Or you can change it to display method_name of selected row:
private void cmbProcessorMethods_SelectedIndexChanged(object sender, EventArgs e)
{
DataRowView row = (DataRowView)cmbProcessorMethods.SelectedItem;
MessageBox.Show(row["method_name"].ToString());
}
As Derek pointed, just set DisplayMember and ValueMember properties before assigning data source and your original code will work:
cmbProcessorMethods.ValueMember = "method_id";
cmbProcessorMethods.DisplayMember = "method_name";
cmbProcessorMethods.DataSource = dt;

Selecting an item in the RadioButtonList, how to get a list of items to a ListBox from database in asp.net c#

I have a RadioButtonList and a ListBox. I have bound RadioButtonList to database.
Therefore upon selecting an item in the RadioButtonList, I want to retrieve some data into the ListBox. The code I have tried is :
protected void Page_Load(object sender, EventArgs e)
{
RadioFill();
}
public void RadioFill()
{
SqlDataAdapter mydata = new SqlDataAdapter("SELECT DISTINCT Param_Name FROM Parameter_Value_Master", con);
DataSet dset = new DataSet();
mydata.Fill(dset, "Table");
RadioButtonList1.Items.Clear();
RadioButtonList1.DataSource = dset.Tables[0];
RadioButtonList1.DataTextField = dset.Tables[0].Columns["Param_Name"].ColumnName;
RadioButtonList1.DataBind();
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlDataAdapter mydata = new SqlDataAdapter("SELECT Value_Option FROM Parameter_Value_Master", con);
DataSet dset = new DataSet();
mydata.Fill(dset, "Table");
ListBox1.Items.Clear();
ListBox1.DataSource = dset.Tables[0];
ListBox1.DataTextField = dset.Tables[0].Columns["Value_Option"].ColumnName;
ListBox1.DataBind();
}
The issue I am facing here is upon selecting an item, the whole panel in which I have placed both my RadioButtonList and ListBox goes invisible.
Kindly help...!! Thankyou...!!
First, change Page_Load method as:
protected void Page_Load(object sender, EventArgs e)ยจ
{
if (!Page.IsPostBack)
{
RadioFill();
}
}
If it not help than post code from your *.aspx file.
Remark: The method RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e),
there is not selecting based on radio button list selected value.

How to show record in DataGridView based on selected ComboBox item?

I am making windows application and am stuck at one place.
My problem is that i want to display record in a DataGridView by selecting a ComboBox item but I do not understand the proper way to do it. Please help me in overcome this problem.
private void grid_Load(object sender, EventArgs e)
{
con = new SqlConnection(constr);
try
{
con.Open();
//this.studTableAdapter.Fill(this.pRJTestDBDataSet.stud);
//above line show error for connection to database
da = new SqlDataAdapter("SELECT stud_no FROM stud", con);
DataTable dt = new DataTable();
da.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "stud_no";
comboBox1.ValueMember = "stud_no";
comboBox1.DataSource = dt;
comboBox1.SelectedIndex = -1;
comboBox1_SelectedIndexChanged(sender, e);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{ con.Close(); }
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.studTableAdapter.Fill(pRJTestDBDataSet.stud);
//above line show error for connection to database
}
i have tried above code but its not working there error like login fail to user
cmd = new SqlCommand("SELECT stud_no FROM stud", con);
da = new SqlDataAdapter(cmd);
da.Fill(dt);
Combobox1.DataSource = dt;
Combobox1.DisplayMember = dt.Columns("Stud_no").ToString;
rebind the DataGrid at each SelectedItemIndex change event of Combo Box by the data you want to bind.
private void button2_Click(object sender, EventArgs e)//button 2 is a show data button
{
if (combo_floor.Text != "")
{
DataSet ds = new DataSet();
string sql = "select floor_id,floor_no,floor_remark,floor_entrydate from Floorinfo where floor_no='"+combo_floor.Text+"'";
ds = c.select_query(sql);
dataGridView1.DataSource = ds.Tables["a"];
combo_floor.Text = "";
}
else
{
showdata();
//showdata()is made for show all data from the given table name
}
}
//connection is in different class so please dont mind

Categories