Ok, the advice by AgaveJoe in your comments?
Pots of gold! - I give him the best year of the advice award!!!
Bootstrap does not by magic write the code and logic for you.
Bootstrap does not pull data for you.
All bootstrap does is format your controls.
And THAT includes the standard web form controls.
It can though some “class” settings in the markup do some cool things (such as pop up a div), but it will not layout, nor will it do the code logic for you.
And keep in mind that asp.net web forms for a good 10 years by default DOES include bootstrap.
They play VERY nice together.
What this means?
You can drop in standard controls (list view, grid view) into your form, and then just “set them” to use bootstrap.
They will as a result?
Look nice!!!
Re-size nice!!!
And look like ANY OTHER application that used bootstrap.
I mean, if you just drop in a gridview?
I was going to post a few screen shots of the grid without boot strap formats, but I’ll just skip onto using bootstrap.
Without boostrap grids and listview really looks “bad”
They don’t re-size very nice etc.
But, do ONE magic thing?
Just set the gv CssClass = "table" and that amazing bootstrap GOES to work for you!!!
And I mean REALLY goes to town!!!
Just try it!!!
Now I don’t have your tables handy, but I do have this:
So, let’s say the grid on the left side – we select a row (Hotel booking) and then on the right side, we display the data from the two child tables
one table is payments, and other is room (hotel options).
rows?
So, drop in the grid in a div.
And the above is in a div, so just float another div to the right
And inside of that floated div, drop in two more for the two grids.
Ok, so the total markup for this is this:
(Unfortantly I can’t past html here)
Hey, it fits in one screen full - not a lot!!!
Note VERY careful for each grid we bootstrapped by setting
Cssclass = table
In fact toss in this:
Table table-hover
You get a beauty cursor row hover effect.
And if you want alternating shaded rows, do this:
Table table-hover table-striped
That’s it – and it now REALLY nice.
So, our main code to load this up is this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
GridView1.DataSource = MyRst("SELECT TOP 12 * FROM tblHotels ORDER BY HotelName")
GridView1.DataBind()
End If
End Sub
We now have this:
Click on a row, and we get this:
Now, lets add the row click code - you can see the button in the markup, we have this code:
Protected Sub cmdView_Click(sender As Object, e As EventArgs)
Dim btn As Button = sender
Dim gRow As GridViewRow = btn.Parent.Parent
If ViewState("MySelRow") <> gRow.RowIndex Then
GridView1.Rows(ViewState("MySelRow")).CssClass = ""
End If
gRow.CssClass = " alert-info"
ViewState("MySelRow") = gRow.RowIndex
Dim hID As Integer = GridView1.DataKeys(gRow.RowIndex).Item("ID")
GHotelOptions.DataSource = MyRst("SELECT * FROM HotelOptions WHERE Hotel_ID = " & hID)
GHotelOptions.DataBind()
GPayments.DataSource = MyRst("SELECT * FROM HotelPayments WHERE Hotel_ID = " & hID)
GPayments.DataBind()
End Sub
So, we just fill the two child grids based on that row click
Now, I never was a big fan of the built in grid events, and things like alternation row template? (please!!!).
So, I just hard coded into viewstate the last row click, and shove in a bootstrap css.
And I pick up the grid row from the button .parent.parent
We now get this:
We are done!
Wait? Really? That’s it????
Yup!!!
Now note how I did use in-line sql, but I NEVER concatenate user input. (the data key is 100% server side.
What does this mean?
99% of what boot strap does is style and make things look pretty.
And they REALLY make the grids and listviews gorgeous.
So, there no need to change much of your world.
Remember, asp.net HAS to crank out valid 100% PURE legal HTML.
If asp.net did not do that? Then it would not work with any browser etc.
Turns out?
Bootstrap WORKS on that HTML output, NOT the asp.net markup!!!
So, bootstrap does NOT care if this is asp.net, vb.net, or web forms – it does NOT matter!!!
Just drop in your buttons, grids etc.,
So don’t dump the built in controls – they will save you boatloads of work, boatloads of looping code, and they 100% will make hugs and love to both you and bootstrap.
In fact, using bootstrap is a fantastic way to upgrade your look and feel, and do so with VERY little efforts on your part.
I mean I count a total of less then what 20 lines of code for a 3 grids and a relational database drill down to two child tables?
Ok, Bob is your uncle on this one!!!
So, you can’t really beat the setup you have, and that includes using standard asp.net controls, and just setting the cssclass for those controls.
Do that, and it pure magic.
Edit:-----------------------------
The poster asked for a c# version. They are much the same, but of course in c# you spend a wee bit more time having to type cast - but here is the same code as c#:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = MyRst("SELECT TOP 12 * FROM tblHotels ORDER BY HotelName");
GridView1.DataBind();
}
}
protected void cmdView_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow gRow = (GridViewRow)btn.Parent.Parent;
if ( (ViewState["MySelRow"] != null) &&
((int)ViewState["MySelRow"] != gRow.RowIndex) )
{
GridView1.Rows[(int)ViewState["MySelRow"]].CssClass = "";
}
gRow.CssClass = "alert-info";
int hID = (int)GridView1.DataKeys[gRow.RowIndex]["ID"];
ViewState["MySelRow"] = gRow.RowIndex;
GHotelOptions.DataSource = MyRst("SELECT * FROM HotelOptions WHERE Hotel_ID = " + hID);
GHotelOptions.DataBind();
GPayments.DataSource = MyRst("SELECT * FROM HotelPayments WHERE Hotel_ID = " + hID);
GPayments.DataBind();
}
public DataTable MyRst(string strSQL)
{
DataTable rstData = new DataTable();
using (SqlCommand cmdSQL = new SqlCommand(strSQL,
new SqlConnection(Properties.Settings.Default.TEST3)))
{
cmdSQL.Connection.Open();
rstData.Load(cmdSQL.ExecuteReader());
}
return rstData;
}
}
Regards,
Albert D. Kallal (Access MVP 2003-2017)
Edmonton, Alberta Canada