Hi
I have one Web form fields countrycode,officedesc . I want when user selects countrycode , it should search in another table having field countrycode and get value from the field last_no when user clicks on Save Button.
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jiteendra SampathiraoPosted Jul 20, 2011, 7:43 AM
I hope you know that how to retrieve the values from database ..........
protected void btnSave_Click(object sender, EventArgs e)
{
DataBinding_Gridview(gvview, RetrieveQuery());
}
DataBinding_Gridview(gvview, RetrieveQuery());
private string RetrieveQuery()
{
string getquery = "";
getquery= "SELECT a,b,c FROM db_table where countrycode "+lstId.selecteditem.value;
return getquery;
}
private void DataBinding_Gridview(GridView gv, string query)
{
DataSet ds = null;
if (gvview.PageIndex == 0)
{
int myindex = 0;
gvview.PageIndex = myindex;
}
DatasetBinding(out ds, query);
gv.DataSource = ds;
gv.DataBind();
}
private void DatasetBinding(out DataSet ds, string query)
{
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["SqlServer"]);
SqlCommand sqlcom = new SqlCommand();
sqlcon.Open();
sqlcom.Connection = sqlcon;
sqlcom.CommandType = CommandType.Text;
sqlcom.CommandText = query;
SqlDataAdapter sqldptr = new SqlDataAdapter(sqlcom);
DataSet dset = new DataSet();
sqldptr.Fill(dset);
ds = dset;
sqlcom.Dispose();
sqlcon.Close();
}
//Page Index
protected void gview_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvview.PageIndex = e.NewPageIndex;
DataBinding_Gridview(gvview, RetrieveQuery());
}
//Row Databound
protected void gview_RowDatabound(object sender, GridViewRowEventArgs e)
{
int page = gvview.PageIndex + 1;
int count = gvview.PageCount;
}
Gridview in design page:
onrowdatabound="gview_RowDatabound" onrowcommand="gv_RowCommand"
onrowediting="gvview_rowediting" onrowdeleting="gvview_rowdeleting" >
<%#Container.DataItemIndex+1 %>
I hope it help you..........
Jagjit SainiPosted Jul 20, 2011, 7:02 AM
I will display countrycode in a listbox , and when user selects countrycode , it should display all the records in gridview from abc table where countrycode = lstbox.selectedcountry , Gridview has 1 select button and when user selects that button gridview column1 value should get stored in Textbox.
Thanks
Jiteendra SampathiraoPosted Jul 20, 2011, 6:24 AM
i didn't understand your question...
implement the functionality under save button click event.....
"select last_no from table-xyz where countrycode= " +txtasasa.text;