private void bindData(int startWeek, int endWeek, WebDataGrid web) { string strSQL = string.Empty; DataTable objTable = new DataTable(); string userMaker=getUserMaker(startWeek, endWeek); } strSQL = "SELECT* FROM table "; objTable = new DataTable("Data"); objTable = objAdoData.RetrieveData2Table(strSQL); web.ClearDataSource(); web.ClearTemplates(); if (objAdoData.Message.Length > 0) { return; } if (web.Columns.Count > 0) { web.Columns.Clear(); } CreateWebDataGridColumns(web, objTable); web.DataSource = objTable; web.DataBind(); }
protected void CreateWebDataGridColumns(WebDataGrid wdg, DataTable dt) { wdg.ClearDataSource(); wdg.ClearTemplates(); wdg.Columns.Clear(); BoundDataField BoundCol = new BoundDataField(); BoundCol.Key = "Maker"; BoundCol.Header.Text = "Maker"; BoundCol.Width = 70; BoundCol.DataFieldName = "Maker"; BoundCol.CssClass = "text-left"; wdg.Columns.Add(BoundCol); for (int i = 1; i < dt.Columns.Count; i++) { TemplateDataField templateCol = new TemplateDataField(); templateCol.Key = dt.Columns[i].ColumnName; templateCol.Header.Text = dt.Columns[i].ColumnName; templateCol.Width = 100; templateCol.ItemTemplate = new CustomItemTemplateByLink(); templateCol.CssClass = "text-right"; wdg.Columns.Add(templateCol); } }
I have four webdatagrid that will bind with different week data.
I use binddata() to pass week range and webdatagrid object.
And I have a dropdownlist that choose year value.
The default is current year. User can change ddl to see every year every week data.
Such as choose 2019 . He can see
bindData(1, 13, wdgData1); bindData(14, 26, wdgData2); bindData(27, 39, wdgData3); bindData(40, 52, wdgData4);
_______________________________
WebDataGrid can display the right data at first time to enter the page.
But when I change the dropdownlist to see different year.
The data show null .
I make sure that the datatable has data that from database.
I don't know why i had bind but they had not shown.
//this is ddl change method
protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e) { string i = ddlYear.SelectedValue; bindData(1, 13, wdgData1); bindData(14, 26, wdgData2); bindData(27, 39, wdgData3); bindData(40, 52, wdgData4); }
// this is pageload method
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { bindData(1, 13, wdgData1); bindData(14, 26, wdgData2); bindData(27, 39, wdgData3); bindData(40, 52, wdgData4); } }
You can see both of them is same calls.
This is first time enter. default 2019 year
When I change ddl to 2018 year , it empty
When I change back to 2019 , the original value can't show.
<ig:WebDataGrid ID="wdgData1" runat="server" AutoGenerateColumns="false" StyleSetName="Default" StyleSetPath="../ig_res" Width="100%" > <Columns> </Columns> <Behaviors> <ig:Activation Enabled="true" /> <ig:ColumnResizing Enabled="false" /> <ig:ColumnFixing ShowLeftSeparator="true" ShowFixButtons="false" /> </Behaviors> </ig:WebDataGrid> <br /> <ig:WebDataGrid ID="wdgData2" runat="server" AutoGenerateColumns="false" StyleSetName="Default" StyleSetPath="../ig_res" Width="100%" > <Columns> </Columns> <Behaviors> <ig:Activation Enabled="true" /> <ig:ColumnResizing Enabled="false" /> <ig:ColumnFixing ShowLeftSeparator="true" ShowFixButtons="false" /> </Behaviors> </ig:WebDataGrid> <br /> <ig:WebDataGrid ID="wdgData3" runat="server" AutoGenerateColumns="false" StyleSetName="Default" StyleSetPath="../ig_res" Width="100%" > <Columns> </Columns> <Behaviors> <ig:Activation Enabled="true" /> <ig:ColumnResizing Enabled="false" /> <ig:ColumnFixing ShowLeftSeparator="true" ShowFixButtons="false" /> </Behaviors> </ig:WebDataGrid> <br /> <ig:WebDataGrid ID="wdgData4" runat="server" AutoGenerateColumns="false" StyleSetName="Default" StyleSetPath="../ig_res" Width="100%" > <Columns> </Columns> <Behaviors> <ig:Activation Enabled="true" /> <ig:ColumnResizing Enabled="false" /> <ig:ColumnFixing ShowLeftSeparator="true" ShowFixButtons="false" /> </Behaviors> </ig:WebDataGrid>
front end code
Sorry, I find the reason why can't show data.
Because I set WebDataGrid.Visible= True, because 2019 have not uploaded any file.
When change to 2018, I forget to open the setting.