I have a 2 usercontrol on a aspx page. 1 control is having search creteria and search button and 2nd usercontrol is having gridview.
How do I bind gridview when user enter creteria and click on search button.
The click event need to be bubbled up to the aspx page and then passed to the gridview usercontrol. See the following link how to bubble events.
http://odetocode.com/code/94.aspx
Considering the 1st UserControl produces a DataTable. Specify a Property in 2nd UserControl which accepts the datatable and bind it to the grid inside the control.
Control2:
public datatable Result{get;set;}
Private void SetGrid()
{
datagrid1.datasource=Result;
datagrid1.databind();
}
Control1:
Datatable dt=SearchResult();
Control2.Result=dt;
In the second user control in .ascx page you can Reference first user control
like as
<%# Reference Control="first user control names comes here" %>
In second user control page load event you can find object of first user control using below mentioed ways:
UserControls_UCFirst uc1 = (UserControls_UCFirst)this.Parent.FindControl("UCFirst1");
then you can find search criteria objects (TextBox, DropDownList, etc..) of first user control.
TextBox txt = (TextBox)(uc1.FindControl("txtName"));
Through above process you can bind grid view.
Hope it will helps.
First Get the searched Results in a DataTable, and Stored the DataTable in a ViewState. And then set the DataTable in a ViewState as datasource of the GridView.
Like this,
GridView1.DataSource = ViewState["DataTable1"];
GridView1.DataBind();
I hope this will help u.
Related
I have a grid of list of companies & below its branches(subgrid within company grid). I have checkbox for each binding with their id's(Companyid & branchid).I have one button to add those selcted values from either company or branch & show all selected record in another grid.Add button is outside of gridview so on click of add button i have to find branch gridview here i can find its parent grid.I wrote following code to find control inside onclick event of add button but its not finding that control:
GridView gvbranch= (GridView)gvcompany.FindControl("gvbranch");
So please help me how i can find that child control in add click event?
Thanks
foreach (GridViewRow row in gv.Rows)
{
TextBox txt = row.Cells[0].Controls[0].FindControl("TextBox1") as TextBox;
string value = txt.Text;
Response.Write(value);
}
use something like this , on button event
There are ASP controls such as radiobuttonlist and checkboxlist and you can databind them to a database query. It's great for creating dynamic lists with user interaction. What I'm trying to do is generate a list of textboxes in the same fashion. A list of textboxes that behave the same way.
The object is to have a checkboxlist that is generated via datasource/database. When the user is finished selecting items from this list, they click a button. That list hides (using jquery) and a new list is created based on their selections. However, the new list is now a list of their selections accompanied by an empty textbox. The user fills in the textboxes for each entry and submits again which commits it to a database.
SO:
checkbox - description
checkbox - description
checkbox - description
checkbox - description
Becomes:
Description - Textbox
Description - Textbox
The reason that I'm looking for a list-type control is so that I can ultimately loop through it for submission to the database using linq. Does that make sense? My real question is if there is a control like this yet. I gave the full description in case someone has any other ideas, short of creating a custom control.
There's nothing out of the box that does what you describe no. But you can still loop through controls. I would put your form controls inside of an asp:Panel or a div with runat="server" and use something like the following code to cycle through them as you described.
foreach(Control ctl in myPanel.Controls)
{
//check control type and handle
if (ctl is TextBox)
{
//handle the control and its value here
}
}
asp:ListBox has a property named SelectionMode, which can be set to SelectionMode="Multiple" and allows you to select items you want. This is not exactly what you need but it's a simple solution.
After the selection is made in checkboxlist, make a postback to server. Here create a datatable with two columns (description & text). For every selected item in the checkboxlist add a row to this table and bind it to a gridview control. Here 'text' column will be always empty. Configure the gridview to use template column with a textbox in the itemtemplate
I am having DropDownList with country name list in my .aspx page and on other page I need the same DropDownList with same data but in GridView.
Is it possible to use that DropDownList ?
You should create a user control that contains this behavior and then you can this user control in several places.
Yes. just create another dropdown box and fill in the same database data in the dropdown inside the gridview.
I have the selected DataKey in session from the ListView.
I am able to set the selection back when I comeback to this aspx page containing listview.
But when the selected item in the listview belongs to some other page (not the first listview page) then I need to also set the selected listview page to the one, where my item belongs.
I use a listview and a datapager (with template paging)
How can I find, in which page my item to be selected exists?
Can I search for the datakey value's page and then activate it?
Well the simplest solution I could apply was to also save the pageindex on session.
protected void ListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{ CurrentPageSessionVariable = (e.StartRowIndex / e.maximumRows);
}
Now on pageload...
dataPager1.SetPageProperties(CurrentPageSessionVariable * dataPager1.PageSize, dataPager1.MaximumRows, true);
This will ensure that when we comeback to this page, the datapager is signaled to load the specified page and show the selected item(which is separate code).
If we select the dropdown list Item then I want to display the Item Particulars in the Gridview Please Help me
On the SelectedIndexChanged of the dropdown rebind your GridView off of the selected value
Add a dropdownlist control, a button control, a grid view and an sqldatasource.
Configure the datasource first in sqldatasource.
I would recommend write a storeprodure to fetch data into the gridview (sqldatasource).
Bound the parameter to "controls" and select the dropdownlist. Now your DDL is bound to the gridivew. In his table click on advance properties and change property convertemptystringto null = false. (there property is something similar).
If you want a button to update the grid view, do this. Add the default event control to the button, put no code in it.
If you want to change the grid view content based on select directly then choose autopost on selected changed in properties of the DDL.
If everything is fine, this should populate your grid view based on contents in DropDownlist