Select dropdownlist accordingly

Posted by Oswaldlily under ASP.NET on 8/9/2011 | Points: 10 | Views : 1345 | Status : [Member] | Replies : 2
I have single column with 10 rows.
5 rows are filled with data
next 5 rows empty

i ve dropdownlsit-listitem-A,B outside gridview
if i click "A" 5 rows with datafilled need 2 display
if iclick "B" 5 rows with empty row need to be display.

tel me how




Responses

Posted by: Hmanjarawala on: 8/9/2011 [Member] Bronze | Points: 25

Up
0
Down
Do one thing,
you might have use DataTable as DataSource to DataList....

Now do one thing, when you click ListItem "A" write Filer Query on DataTable.DefaultView which fetch Row with Data n vice-versa.

Assign DataTable.DefaultView as DataSource to DataList

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ashoknalam on: 8/9/2011 [Member] Starter | Points: 25

Up
0
Down
I did a sample application which might useful for you. please change your logic accordingly

Codebehind file:



  protected void Page_Load(object sender, EventArgs e)

{

BindGrid("A");

}
public void BindGrid(string filter)
{
DataTable dt = new DataTable();
DataColumn dc = new DataColumn();
dc.ColumnName = "Items";
dc.Caption = "Sample Items with first 5 Rows strings and next 5 as blanks";
dt.Columns.Add(dc);
int rowsCount = 10;
DataRow dr;
for (int index = 1; index <= rowsCount; index++)
{

dr = dt.NewRow();
if (index <= 5)
{
dr["Items"] = "Item" + index.ToString();
}
else
{
dr["Items"] = "";
}
dt.Rows.Add(dr);
}

DataSet ds = new DataSet();
ds.Tables.Add(dt);

DataView dv = new DataView(dt);
if(filter=="A")
{
dv.RowFilter = "Items<>''";
}
else if (filter == "B")
{
dv.RowFilter = "Items=''";
}


GridView1.DataSource = dv;
GridView1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid(DropDownList1.SelectedItem.Text);
}


ASPX file:
     <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 

onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="A"></asp:ListItem>
<asp:ListItem Text="B"></asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>



please mark it as "Mark As Answer" if you find useful.

Ashok Nalam

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response