define sqlparameter array for those and pass that array to that method, also pass 1 as flag, if the flag is 1, then add those parameters to that command.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView GridView1 = new GridView();
foreach (GridViewRow gvRow in GridView1.Rows)
{
int ID = Convert.ToInt32(GridView1.DataKeys[gvRow.RowIndex]["ID"]);
RadioButtonList rbAnswers = (RadioButtonList)gvRow.FindControl("RadioButtonList1");
using (SqlConnection con = new SqlConnection("your connection string"))
{
SqlCommand cmd = new SqlCommand("insert into answerstablename values (@id,@answerid)", con);
cmd.Parameters.AddWithValue("id", ID);
cmd.Parameters.AddWithValue("answerid", Convert.ToInt32(rbAnswers.SelectedValue));
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
}
protected void GridView1_PreRender(object sender, EventArgs e)
{
if (GridView1.EditIndex != -1)
{
((TextBox)GridView1.Rows[GridView1.EditIndex].Cells[1].Controls[0]).Text = "ram";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class index : System.Web.UI.Page
{
PagedDataSource pagedData = new PagedDataSource();
void Page_Load(Object obj, EventArgs e)
{
getTheData("sp_customersdefault",0,null);
}
public void getTheData(string procname,int Flag, SqlParameter[] sqlparams)
{
DataSet DS = new DataSet();
SqlConnection objSQLConn = new SqlConnection(ConfigurationManager.ConnectionStrings["MarkConnectionString"].ConnectionString);
SqlDataAdapter objSQLAdapter = new SqlDataAdapter(procname, objSQLConn);
objSQLAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
if(Flag == 1)
{
objSQLAdapter.SelectCommand.Parameters.AddRange(sqlparams);
}
objSQLAdapter.Fill(DS, "customers");
pagedData.DataSource = DS.Tables[0].DefaultView;
pagedData.AllowPaging = true;
pagedData.PageSize = 9;
try
{
pagedData.CurrentPageIndex = Int32.Parse(Request["Page"].ToString());
}
catch (Exception ex)
{
pagedData.CurrentPageIndex = 0;
}
btnPrev.Visible = (!pagedData.IsFirstPage);
btnNext.Visible = (!pagedData.IsLastPage);
DataList1.DataSource = pagedData;
DataList1.DataBind();
}
public void Prev_Click(Object obj, EventArgs e)
{
Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pagedData.CurrentPageIndex - 1));
}
public void Next_Click(Object obj, EventArgs e)
{
Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pagedData.CurrentPageIndex + 1));
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlParameter[] sqlparams = new SqlParameter[1];
sqlparams[0].ParameterName = "param1";
sqlparams[0].Value = "value1";
sqlparams[0].DbType = DbType.String;
getTheData("stored proc name here",1,sqlparams);
//I would like to dynamically fill the dataset with a different stored procedure here
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlParameter[] sqlparams = new SqlParameter[1];
sqlparams[0].ParameterName = "fsdfs";
sqlparams[0].Value = "fsdfs";
sqlparams[0].DbType = DbType.String;
getTheData("stored proc name here",1,sqlparams);
//I would like to dynamically fill the dataset with a different stored procedure here
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
SqlParameter[] sqlparams = new SqlParameter[1];
sqlparams[0].ParameterName = "paramx";
sqlparams[0].Value = "fsd";
sqlparams[0].DbType = DbType.String;
getTheData("stored proc name here",1,sqlparams);
//I would like to dynamically fill the dataset with a different stored procedure here
}
}
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.