ASP.NET - update in gridview with radiobtn

Asked By Rahul
10-Feb-12 02:23 AM
i have 2 agent & member table it is successfully updated, but  in gridview i have select radiobtnlist as agent to member means it want to add the record automatically agent to member table how ?

or tel how to modify in my codings using radiobtnlist ? my coding as below:

if (RadioButtonList1.SelectedIndex == 0)

{
else if (e.CommandName == "upd") 1
codings...... ...how ?

}

 else if (RadioButtonList1.SelectedIndex == 1)

{
else if (e.CommandName == "upd") 2
codings.... //how ?

}



}//here codings...

else if (e.CommandName == "upd")  1

{

LinkButton lkbupd = (LinkButton)e.CommandSource as LinkButton;

 

GridViewRow row = lkbupd.NamingContainer as GridViewRow;

Label lbid = (Label)row.FindControl("lblid");

 

TextBox txfrdate = (TextBox)row.FindControl("txtfrdate");

TextBox txtodate = (TextBox)row.FindControl("txttodate");

 

TextBox txtitle = (TextBox)row.FindControl("txttitle");

TextBox txdescription = (TextBox)row.FindControl("txtdescription");

 

RadioButtonList txradiocategory = (RadioButtonList)row.FindControl("radiotype");

 

cmd=new SqlCommand("update agentoffer set fromdate='"+txfrdate.Text+"',todate='"+txtodate.Text+"',title='"+txtitle.Text+"',description='"+txdescription.Text+"',category='"+txradiocategory.SelectedItem.Text+"' where id='"+lbid.Text+"'",con);

cmd.ExecuteNonQuery();

GridView1.EditIndex = -1;

Response.Write(

"Updated Successfully");

bindgrid();

}

else if (e.CommandName == "del")

{

 

LinkButton lnkdel = (LinkButton)e.CommandSource as LinkButton;

GridViewRow row = lnkdel.NamingContainer as GridViewRow;

 

Label lid = (Label)row.FindControl("lblid");

cmd = new SqlCommand("delete from agentoffer where id='" + lid.Text + "'", con);

cmd.ExecuteNonQuery();

Response.Write(

"Deleted Successfully");

bindgrid();

}

else if (e.CommandName == "Edit")

{

 

LinkButton lnkedit = (LinkButton)e.CommandSource as LinkButton;

GridViewRow row = lnkedit.NamingContainer as GridViewRow;

lbradio = (

Label)row.FindControl("lblcategory");

}










else if (e.CommandName == "upd")    2

{

LinkButton lkbupd = (LinkButton)e.CommandSource as LinkButton;

 

GridViewRow row = lkbupd.NamingContainer as GridViewRow;

Label lbid = (Label)row.FindControl("lblid");

 

TextBox txfrdate = (TextBox)row.FindControl("txtfrdate");

TextBox txtodate = (TextBox)row.FindControl("txttodate");

 

TextBox txtitle = (TextBox)row.FindControl("txttitle");

TextBox txdescription = (TextBox)row.FindControl("txtdescription");

 

RadioButtonList txradiocategory = (RadioButtonList)row.FindControl("radiotype");

 

 

cmd=new SqlCommand("update memoffer set fromdate='"+txfrdate.Text+"', todate='"+txtodate.Text+"', title='"+txtitle.Text+"', description='"+txdescription.Text+"', category='"+txradiocategory.SelectedItem.Text+"' where id='"+lbid.Text+"'",con);

cmd.ExecuteNonQuery();

GridView2.EditIndex = -1;

Response.Write(

"Updated Successfully");

bindgrid1();

}










  dipa ahuja replied to Rahul
10-Feb-12 05:55 AM
If the updating based on the radiobutton value then check it this way, first use only one command for the update and at that event just check  the radiobutton's selected value

protected void GridView1d_RowCommand(object sender, GridViewCommandEventArgs e)
{
  if (e.CommandName == "Update")
  {
    GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
    //get raidobutton selected value
 
    RadioButtonList rd1 = (RadioButtonList)row.FindControl("radio1");
    if (rd1.SelectedItem.Text == "Agent")
    {
      //code to execute
    }
    else if (rd1.SelectedItem.Text == "Member")
    {
      //code to execute
    }
  }
}

Create New Account
help
0" border = "0" class = "ThreeColumnLayout"> <!- - Field Row - -> < tr > <!- - Column 1 - -> < td class = "FormFieldLayoutCell ThreeColumnLabelCell"> < asp : Label ID = "lblReOpenedTicketNumber" runat = "server" Text = "Ticket #:" Font-Bold = "True"> < / asp : Label > < / td > < td class = "FormFieldLayoutCell ThreeColumnFieldCell"> < asp : Label ID = "lblReOpenedTicketNumberDisplay" runat = "server" Text = "-" Font-Bold = "True" CssClass = "FormFieldLayoutFormElement"> < / asp : Label > < / td > <!- - Column 2 - -> < td class = "FormFieldLayoutCell ThreeColumnLabelCell"> &nbsp; < / td > < td class = "FormFieldLayoutCell ThreeColumnFieldCell"> &nbsp; < / td FormFieldLayoutCell ThreeColumnFieldCell"> &nbsp; < / td > < / tr > <!- - Field Row - -> < tr > <!- - Column 1 - -> < td class = "FormFieldLayoutCell ThreeColumnLabelCell"> < asp : Label ID = "LabelReOpenedTicketStatus" runat = "server" Text = "Status:"> < / asp : Label > < / td > < td class = "FormFieldLayoutCell ThreeColumnFieldCell"> < KORE : uxLookupFieldTicketStatus runat = "server" ID = "uxLookupFieldReOpenedTicketStatus" CssClass = "FormFieldLayoutFormElement" / > < / td > <!- - Column 2 - -> < td class = "FormFieldLayoutCell ThreeColumnLabelCell"> < asp : Label ID = "LabelReOpenedAssignedTo" runat = "server" Text = "Assigned to:"> < / asp Label > < / td > < td class = "FormFieldLayoutCell ThreeColumnFieldCell"> < KORE : uxLookupFieldTicketAssignedTo runat = "server" ID = "uxLookupFieldReOpenedTicketAssignedTo" CssClass = "FormFieldLayoutFormElement" / > < / td > <!- - Column
Control Language = "C#" AutoEventWireup = "true" CodeFile = "PreviewPost.ascx.cs" Inherits = "CandidateControl_PreviewPost" %> <table > <tr> <td> <asp:Label ID = "Label1" runat = "server" Text = "Resume Name"> < / asp:Label> < / td> <td> <asp:Label ID = "Label2" runat = "server" Text = "Label"> < / asp:Label> < / td> <td> &nbsp;< / td> < / tr> <tr> <td> <asp:Label ID = "Label3" runat = "server" Text = "Desired Position"> < / asp Label> < / td> <td> <asp:Label ID = "Label4" runat = "server" Text = "Label"> < / asp:Label> < / td> <td> &nbsp;< / td> < / tr> <tr> <td
foreach in gridview this is for each for radio button in gridview foreach ( GridViewRow row in GridView1.Rows) { RadioButtonList txgender = ( RadioButtonList )row.FindControl( "radiogender" ); if (txgender ! = null ) { if (lbgender.Text = = "Male" ) { txgender.SelectedIndex = 0; } else { txgender this above shown ? how to write coding fro this ? Hello, Try as following way foreach ( GridViewRow row in GridView1.Rows) { DropDownList drp = ( DropDownList )row.FindControl( "drp" ); foreach ( ListItem item in drp Page { SqlConnection con = new SqlConnection ( ConfigurationManager .ConnectionStrings[ "rafi" ].ConnectionString); SqlCommand cmd; SqlDataAdapter adap; DataSet ds; Label dropdown = new Label (); Label dopdown = new Label (); protected void Page_Load( object sender, EventArgs e) { if (!IsPostBack) { / / bindgrid(); dropbind(); dropbind1(); } } protected void Button3_Click
data in gridview using checkbox hi I am having a gridview with checkboxes , textboxes and radiobuttonlist.here i want to update a row in gridview using gridview if checkbox is checked chk = ( CheckBox )GridView1.Rows[e.RowIndex].FindControl( "CheckBox1" ); if (chk.Checked) { int id = int .Parse((( Label )GridView1.Rows[e.RowIndex].FindControl( "lblid" )).Text); / / ID string name = (( TextBox )GridView1.Rows[e.RowIndex new SqlCommand (q, connect); comm.Parameters.AddWithValue( "name" , name); comm.Parameters.AddWithValue( "id" , id); comm.ExecuteNonQuery(); connect.Close(); GridView1.EditIndex = -1; / / Re- BindGrid(); } } Hi, try this first < asp:GridView ID = "grdCountry the gridview with datatable on code bind write this code protected void grdCountry_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName = = "check") { do your code here; } } hope this will help you / / to to temporay table DataTable seconddt = new DataTable (); seconddt.Columns.Add( "studentid" , typeof (System. Int32 )); foreach ( GridViewRow row in grdvStudent.Rows) { CheckBox chkStudentInfo = ( CheckBox )row.FindControl( "chkStudentInfo" ); TextBox TxtStudID = ( TextBox )row.FindControl SqlCommand ( "attendancesessioninsert" , con.Conn); cmd.CommandType = CommandType .StoredProcedure; cmd.Parameters.AddWithValue( "@studentid" , dr["studentid"]); cmd.ExecuteNonQuery(); con.Conn.Close(); } } cmd.ExecuteNonQuery(); step 1 : add CheckBox Column to your GridView first then you can delete Selected rows Database like below code Step 2 : Code protected void btnDeleteSelected_Click( object sender, EventArgs e) { foreach (GridViewRow row in GridView1.Rows) { if (((CheckBox)row.FindControl( "checkBox1" )).Checked = = true ) { / * Get Table Id From