How to bind the Gridview dropdown and how can i get Dropdown select value in asp.net
I have a develop a asp.net webapplication in that i have gridview control when i load the form gridview hava fill with data which is getting from sqlserver database .In that gridview i have dropdown when i click the edit the form i have selected the values from dropdown and saved into data base but dropdown value always take first index value didn't take selected value please help me....how can i resolve this i have post my code here what i did for that .
protected void grd_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txt = null;
TextBox clientpmtdate = null;
TextBox amt = null;
TextBox PaymentID = null;
try
{
clientpmtdate = ((TextBox)(grdviewPayments.Rows[e.RowIndex].FindControl("txtEditpmtdate")));
int ddldmthd = Convert.ToInt32(((DropDownList)(grdviewPayments.Rows[e.RowIndex].FindControl("ddldebitmethodedit"))).SelectedValue);
int ddlpmtype = Convert.ToInt32(((DropDownList)(grdviewPayments.Rows[e.RowIndex].FindControl("ddlpmttypeedit"))).SelectedValue);
txt = ((TextBox)(grdviewPayments.Rows[e.RowIndex].FindControl("txtEditmtrsvrdate")));
amt = ((TextBox)(grdviewPayments.Rows[e.RowIndex].FindControl("txtEditammount")));
PaymentID = ((TextBox)(grdviewPayments.Rows[e.RowIndex].FindControl("txtEditPaymentID")));
string clienteditpmtdate = clientpmtdate.Text;
// string debitmethod = ddldmthd.SelectedItem.Value;
//string pmttype = ddlpmtype.SelectedItem.Value;
string txtEditmtrsvrdate = txt.Text;
string txtEditammount = amt.Text;
开发者_StackOverflow中文版 string txtEditPaymentID = PaymentID.Text;
int pmtid = Convert.ToInt32(txtEditPaymentID);
string pmtcmnts = txtpmtcmnts.Text;
if (txtEditPaymentID != null)
{
var Editpmt = (from k in mortgageentity.Payments where k.Pmt_ID == pmtid select k).First();
Editpmt.Client_Pmt_Date = Convert.ToDateTime(clienteditpmtdate);
Editpmt.MtgSvr_Pmt_Start_Date2 = txtEditmtrsvrdate;
Editpmt.Amt = Convert.ToDecimal(txtEditammount);
Editpmt.Pmt_Comments = pmtcmnts;
Editpmt.Payment_Type_ID = ddlpmtype;
Editpmt.Debit_Method_ID = ddldmthd;
mortgageentity.SaveChanges();
}
grdviewPayments.EditIndex = -1;
// bindGrid(e.RowIndex + 1, txt.Text);
//bindGrid(0, null);
BindData();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
if (txt != null) txt = null;
}
}
Set the index of dropdown in RowEditing:
protected void grdviewPayments_RowEditing(object sender, GridViewEditEventArgs e)
{
grdviewPayments.EditIndex = e.NewEditIndex;
GridViewRow editingRow = grdviewPayments.Rows[e.NewEditIndex];
DropDownList ddl = (editingRow.FindControl("ddlS") as DropDownList);
if (ddl != null)
{
//set index
}
}
do you enable Postback Property of DropdownList ? IF No then set Postback=True . you coding is right.
精彩评论