Why is my data not showing in my GridView? [duplicate] - c#

This question already exists:
how to show data in gridview from arraylist in asp.net?
Closed 8 years ago.
I have a database where there is userid, problemname and status column. I am retrieving this data from database in an ArrayList and returning it. Now to show in GridView I have taken a DataTable and in the DataTable I have put three columns and I just want to show my data that is saved in the ArrayList in these columns by making one row.
Here is my code:
protected void Page_Load(object sender, EventArgs e)
{
ArrayList myArrayList = ConvertDataSetToArrayList();
// Display each item of ArrayList
DataTable dt = new DataTable();
dt.Columns.Add("User Id");
dt.Columns.Add("Problem Name");
dt.Columns.Add("Status");
foreach (Object row in myArrayList)
{
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["User Id"] = ((DataRow)row)["userid"].ToString();
dt.Rows[dt.Rows.Count - 1]["Problem Name"] = ((DataRow)row) ["problemname"].ToString();
dt.Rows[dt.Rows.Count - 1]["Status"] = ((DataRow)row)["status"].ToString();
}
GridView1.DataSource =dt;
GridView1.DataBind();
}
public ArrayList ConvertDataSetToArrayList()
{
string con = " ";
con = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection objsqlconn = new SqlConnection(con);
objsqlconn.Open();
SqlCommand cmd = new SqlCommand("SELECT userid,problemname,status FROM problemtable", objsqlconn);
cmd.ExecuteNonQuery();
cmd.CommandType = CommandType.Text;
SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.SelectCommand = cmd;
DataSet myDataSet = new DataSet();
myAdapter.Fill(myDataSet);
ArrayList myArrayList = new ArrayList();
foreach (DataRow dtRow in myDataSet.Tables[0].Rows)
{
myArrayList.Add(dtRow);
}
objsqlconn.Close();
return myArrayList;
}
Here is my html:
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText="cdd">
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
Why is my data is not showing in my GridView?

You need to bind your data to specific controls in your gridview. For example, you need to have labels in your gridview itemtemplate to bind your data to. Here is an example:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText="cdd">
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="User Id">
<ItemTemplate>
<asp:Label ID="lbl_userid" runat="server" Text='<%# Eval("User Id") %>' CssClass="lbl"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Problem Name">
<ItemTemplate>
<asp:Label ID="lbl_problemname" runat="server" Text='<%# Eval("Problem Name") %>' CssClass="lbl"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="status">
<ItemTemplate>
<asp:Label ID="lbl_status" runat="server" Text='<%# Eval("Status") %>' CssClass="lbl"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

I agree that an ArrayList is a poor choice, but, regardless of how you're binding the data, you need to tell the gridview what it's supposed to show. You can do this using inline tags or by using an onitemdatabound trigger. I recommend you look up some more examples of gridviews.

Related

Dropdownlist displaying two gridviews

I currently have a drop down list that on selected index changed it displays data in a GridView based of the value of the drop down list. However, it is displaying the data in the existing GridView and then displaying another gridview next to the existing one with the exact information. I am just trying to display the data in the existing open.
C# Code:
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
DataTable table = new DataTable();
using (SqlConnection con = new SqlConnection(#"Data Source=
(local)\;Initial Catalog=SmallBatch;Integrated Security=True;"))
{
con.Open();
SqlDataAdapter DataAdapter = new SqlDataAdapter(string.Format("SELECT Item.ItemID, Item.ItemDesc, Stock_Take_Item.BarQuantity, Stock_Take_Item.StorageQuantity FROM Item INNER JOIN Stock_Take_Item ON Item.ItemID = Stock_Take_Item.ItemID INNER JOIN Stock_Take ON Stock_Take_Item.StockTakeIDNew = Stock_Take.StockTakeIDNew where Stock_Take.Username = '" + DropDownList1.SelectedValue + "'"), con);
DataAdapter.Fill(table);
}
GridView1.DataSource = table;
GridView1.DataBind();
}
}
Existing Gridview:
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<Columns>
<asp:TemplateField HeaderText="Item ID" HeaderStyle-CssClass="gridview-header">
<ItemTemplate>
<asp:Label ID="itemIDAdmin" Text='<%# Eval("ItemID")%>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Description" HeaderStyle-CssClass="gridview-header">
<ItemTemplate>
<asp:Label ID="itemDescAdmin" Text='<%# Eval("ItemDesc")%>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Bar Quantity" HeaderStyle-CssClass="gridview-header">
<ItemTemplate>
<asp:Label ID="barQuantityAdmin" Text='<%# Eval("BarQuantity")%>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Storage Quantity" HeaderStyle-CssClass="gridview-header">
<ItemTemplate>
<asp:Label ID="storageQuantityAdmin" Text='<%# Eval("StorageQuantity")%>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Unable to bind multiple dropdownlist in gridview on editing a row

I've two columns Customer Type and File Frequency in the gridview. When the grid is in normal mode I show the values using label. On editing the row, those two columns become dropdowns. I bind the dropdowns using OnRowDataBound="RowDataBound". But, Only first dropdown(whichever first written in the method) in the RowDataBound method getting bind on the edit mode.
.aspx
<asp:GridView ID="gvManageCustomers" DataKeyNames="Ship_To" runat="server" AutoGenerateColumns="False"
OnRowEditing="EditCustomer" OnRowDataBound="RowDataBound" OnRowUpdating="UpdateCustomer"
OnRowCancelingEdit="CancelEdit" CssClass="table table-bordered table-condensed">
<Columns>
<asp:TemplateField HeaderText="Customer Type">
<ItemTemplate>
<asp:Label ID="lblCustType" runat="server" Text='<%# Eval("Customer_Type")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblCustType" runat="server" Text='<%# Eval("Customer_Type")%>' Visible="false">
</asp:Label>
<asp:DropDownList ID="ddlgvCustomerType" runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="File Frequency">
<ItemTemplate>
<asp:Label ID="lblFileFreq" runat="server" Text='<%# Eval("FileFrequency")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblFileFreq" runat="server" Text='<%# Eval("FileFrequency")%>' Visible="false"></asp:Label>
<asp:DropDownList ID="ddlgvFileFreq" runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
.cs
public DataTable FetchCustomerType()
{
string sql = "select distinct Customer_TypeID,Customer_Type from tbl_CustomerType";
SqlDataAdapter da = new SqlDataAdapter(sql, constr);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable FetchFileFrequency()
{
string sql = "SELECT distinct FileFrequency_ID,FileFrequency FROM [tbl_FileFrequency]";
SqlDataAdapter da = new SqlDataAdapter(sql, constr);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList ddlgvFileFreq = (DropDownList)e.Row.FindControl("ddlgvFileFreq"); //getting binded
ddlgvFileFreq.DataSource = FetchFileFrequency();
ddlgvFileFreq.DataTextField = "FileFrequency";
ddlgvFileFreq.DataValueField = "FileFrequency_ID";
ddlgvFileFreq.DataBind();
ddlgvFileFreq.Items.FindByValue((e.Row.FindControl("lblFileFreq") as Label).Text).Selected = true;
DropDownList ddlgvCustomerType = (DropDownList)e.Row.FindControl("ddlgvCustomerType");
ddlgvCustomerType.DataSource = FetchCustomerType();
ddlgvCustomerType.DataTextField = "Customer_Type";
ddlgvCustomerType.DataValueField = "Customer_TypeID";
ddlgvCustomerType.DataBind();
ddlgvCustomerType.Items.FindByValue((e.Row.FindControl("lblCustType") as Label).Text).Selected = true;
}
}
}
catch (Exception ex)
{
//log error
errorlog.WriteErrorLog(ex.ToString());
}
}
The problem is in this line, it trows an exeption. That's why only the topmost binding would work.
ddlgvFileFreq.Items.FindByValue((e.Row.FindControl("lblFileFreq") as Label).Text).Selected = true;
But it looks like you want the DropDownList to have the correct SelectedValue. This is how you can do that.
DataRowView row = e.Row.DataItem as DataRowView;
DropDownList ddlgvFileFreq = (DropDownList)e.Row.FindControl("ddlgvFileFreq");
ddlgvFileFreq.DataSource = FetchFileFrequency();
ddlgvFileFreq.DataTextField = "FileFrequency";
ddlgvFileFreq.DataValueField = "FileFrequency_ID";
ddlgvFileFreq.DataBind();
try
{
ddlgvFileFreq.SelectedValue = row["FileFrequency_ID"].ToString();
}
catch
{
}
DropDownList ddlgvCustomerType = (DropDownList)e.Row.FindControl("ddlgvCustomerType");
ddlgvCustomerType.DataSource = FetchCustomerType();
ddlgvCustomerType.DataTextField = "Customer_Type";
ddlgvCustomerType.DataValueField = "Customer_TypeID";
ddlgvCustomerType.DataBind();
try
{
ddlgvCustomerType.SelectedValue = row["Customer_TypeID"].ToString();
}
catch
{
}
<asp:TemplateField HeaderText="Customer Type">
<ItemTemplate>
<asp:Label ID="lblCustType" runat="server" Text='<%# Eval("Customer_Type")%>'></asp:Label>
<asp:Label ID="lblCustTypeID" runat="server" Visible="false" Text='<%# (Eval("Customer_TypeID")) %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlgvCustomerType" runat="server" DataSource="<%# FetchCustomerType() %>" DataValueField="Customer_TypeID" DataTextField="Customer_Type" >
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="File Frequency">
<ItemTemplate>
<asp:Label ID="lblFileFreq" runat="server" Text='<%# Eval("FileFrequency")%>'></asp:Label>
<asp:Label ID="lblFileFreqID" runat="server" Visible="false" Text='<%# (Eval("FileFrequency_ID")) %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlgvFileFreq" runat="server" DataSource="<%# FetchFileFrequency() %>" DataValueField="FileFrequency_ID" DataTextField="FileFrequency" >
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
In onRowEditing Event
((DropDownList)gvManageCustomers.Rows[e.NewEditIndex].Cells[0].FindControl("ddlgvCustomerType")).SelectedValue = ((Label)gvManageCustomers.Rows[e.NewEditIndex].Cells[0].FindControl("lblCustTypeID")).Text;
((DropDownList)gvManageCustomers.Rows[e.NewEditIndex].Cells[0].FindControl("ddlgvFileFreq")).SelectedValue = ((Label)gvManageCustomers.Rows[e.NewEditIndex].Cells[0].FindControl("lblFileFreqID")).Text;

GridView in LoginView giving wrong row count

I have a GridView within a LoginView that I am getting an Index Out Of Range error with. When I display the # of rows in the GridView it always shows 0 which is causing this error.
Is there something specific that I need to be doing to get a GridView
to properly work within a LoginView?
Below is the code that is being run when I click on a button in the GridView and the error only comes up on the GridView row = gv.Rows[e.RowIndex]; line. If I use only e.RowIndex I do not get the error and it will actually return the proper number. If I do gv.DataKeys.Count it will return the correct count. If I do gv.Rows.Count it will always be 0. I think it has something to do with a PostBack because if I do a row count in my page_load then it returns the correct count. Please let me know if there is anything else that you need for me to post?
protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
GridView gv = ReviewLoginView.FindControl("gvReview") as GridView;
GridViewRow row = gv.Rows[e.RowIndex];
string Id = (row.FindControl("lblID") as Label).Text;
string constr = System.Configuration.ConfigurationManager.AppSettings["ObservationCardCS"];
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("cardReview"))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#id", Id);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
gv.EditIndex = -1;
this.BindGrid();
}
catch (Exception ex)
{
GridView gv = ReviewLoginView.FindControl("gvReview") as GridView;
int index = e.RowIndex;
lblError.ForeColor = System.Drawing.Color.Red;
lblError.Text = ex.Message + " " + index.ToString() + " " + gv.Rows.Count;
}
}
Below is the LoginView from the aspx page.
<asp:LoginView runat="server" ViewStateMode="Disabled" ID="ReviewLoginView">
<LoggedInTemplate>
<%--<AnonymousTemplate>--%>
<div>
<asp:GridView ID="gvReview" runat="server" AutoGenerateColumns="false" DataKeyNames="ID"
OnRowDataBound="OnRowDataBound" OnRowDeleting="OnRowDeleting" EnableViewState="true"
EmptyDataText="No records have been added." AllowSorting="true" ShowHeaderWhenEmpty="true"
AlternatingRowStyle-BackColor="#e0e0e0" HeaderStyle-BackColor="#d0d0d0" ViewStateMode="Disabled"
EnableSortingAndPagingCallbacks="false">
<Columns>
<asp:TemplateField HeaderText="ID" ShowHeader="false" Visible="true">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>' CssClass="cmsID"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="User">
<ItemTemplate>
<asp:Label ID="lblSubmittedBy" runat="server" Text='<%# Eval("submittedBy") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location">
<ItemTemplate>
<asp:Label ID="lblLocation" runat="server" Text='<%# Eval("location") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lblSubmittedDate" runat="server" Text='<%# Eval("submittedDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="What Was Observed?">
<ItemTemplate>
<asp:Label ID="lblWhatWasObserved" runat="server" Text='<%# Eval("whatWasObserved") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="What Action Was Taken?">
<ItemTemplate>
<asp:Label ID="lblWhatActionWasTaken" runat="server" Text='<%# Eval("whatActionWasTaken") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="What Agreement Was Reached?">
<ItemTemplate>
<asp:Label ID="lblWhatAgreementWasReached" runat="server" Text='<%# Eval("whatAgreementWasReached") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="btnSubmit" runat="server" Text="Edit" CssClass="editbutton" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Review" ButtonType="Button" ShowDeleteButton="true" DeleteText="Review" />
</Columns>
</asp:GridView>
</div>
</LoggedInTemplate>
<%--</AnonymousTemplate>--%>
<AnonymousTemplate>
You must login to view submitted Observation Cards.
</AnonymousTemplate>
</asp:LoginView>
Below is the BindGrid()
private void BindGrid()
{
try
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ObservationCardCS"]);
{
SqlCommand comm = new SqlCommand("cardSelectNew2", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = comm;
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.AddWithValue("#Begin", "1/1/1950");
comm.Parameters.AddWithValue("#End", "12/31/2049");
comm.Parameters.AddWithValue("#Reviewed", "0");
comm.Parameters.AddWithValue("#OrderBy", "CH.id");
comm.Parameters.AddWithValue("#AscDesc", "Asc");
comm.Parameters.AddWithValue("#DateRange", "Last 30 Days");
comm.Connection = conn;
sda.SelectCommand = comm;
DataTable dt = new DataTable();
sda.Fill(dt);
GridView gv = ReviewLoginView.FindControl("gvReview") as GridView;
gv.DataSource = dt;
gv.DataBind();
}
}
catch (Exception ex)
{
lblError.ForeColor = System.Drawing.Color.Red;
lblError.Text = ex.Message;
}
}
Below is my page_load
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
lblError.ForeColor = System.Drawing.Color.Black;
lblError.Text = "";
}
}
You are on the right track! But without seeing the whole class and markup we can only speculate.
Check that you are not clearing or rebuilding the data on the page load event handler, if the Grid and datasource is defined in the markup then it should cache or requery the data between page postbacks, check that you have set EnableRowCache on the GridView so that you dont have to re-query for the data during postbacks.
It looks like you are using the #OldSchool BindGrid() data load pattern, perhaps the simplest solution may be to ensure that the data is loaded first by calling BindGrid before you try to access the rows:
protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
{
this.BindGrid();
try
{
... delete logic
this.BindGrid(); // re-load after the change
}
catch (Exception ex)
{
...
}
}
Without enabling the row cache though you have to ensure that the same data is loaded into the grid in the same order or delete logic like this based on row index (instead of the primary key of the row) could result in you deleting the wrong data row.

Save Grid View Textbox Data to database

I am trying to save grid view text box value and two other text box that are filled by user that are Total Marks and Marks Scored to data base am not sure how to pass back the values of that textboxs to data base on one click of submit
DB where the value to be saved are
Studentname RegNo TotalMarks Marksscored
asdsa 22 125 22
My Gridview
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Names">
<ItemTemplate>
<asp:TextBox ID="txtStudent_Name" runat="server" Text='<%# Eval("StudentFirstName") %>' ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Register Number">
<ItemTemplate>
<asp:TextBox ID="txtreg_number" runat="server" Text='<%# Eval("StudentRegID") %>' ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Marks">
<ItemTemplate>
<asp:TextBox ID="txttotal_marks" runat="server" Text='' ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Marks Scored">
<ItemTemplate>
<asp:TextBox ID="txtmarks_scored" runat="server" Text='' ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
DataTable dt = new DataTable();
DataRow row = dt.NewRow();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
TextBox txtUsrId=(TextBox)GridView1.Rows[i].FindControl("Your textbox id");
string UserID = txtUsrId.Text;
string q="insert into details (name) values('"+UserID+"')";
SqlCommand cmd = new SqlCommand(q, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
}

How to bind objectdatasource with a Gridview

UPDATE: THIS IS THE WORKING VERSION.
public DataSet GetObjects()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
var source = from p in CommentsList
select new { p.Img, p.Name, p.Comment };
dt.Columns.Add("Img");
dt.Columns.Add("Name");
dt.Columns.Add("Comment");
foreach (var item in source)
{
DataRow userDetailsRow=dt.NewRow();
userDetailsRow["Img"] = item.Img;
userDetailsRow["Name"] = item.Name;
DataRow comments = dt.NewRow();
userDetailsRow["Comment"] = item.Comment;
dt.Rows.Add(userDetailsRow);
//dt.Rows.Add(comments);
}
ds.Tables.Add(dt);
return ds;
}
My GridView columns section looks like this:
<Columns>
<asp:TemplateField HeaderText="#">
<HeaderStyle Width="500px" />
<ItemStyle Width="500px" Height="100px" />
<ItemTemplate>
<asp:Label ID="lblMessage" runat="server" Text='<%# Bind("Comment") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="#">
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" Height="100px" />
<ItemTemplate>
<asp:Image ID="imgName" runat="server" imageUrl='<%# Bind("Img") %>'></asp:Image><br />
<asp:Hyperlink ID="hyperLink" runat="server" Text='<%# Bind("Name") %>' ></asp:Hyperlink>
</ItemTemplate>
</asp:TemplateField>
UPDATE: The problem that I have got now is with the size of rows..that are huge and dont update with the content within,,,example: Header 33%, Row 33%, footer 33%..even though the content of the header is 10% of the gridview..how do i fix that?
You do not have a Img property. Plain and simple. This is why you have problems accessing it: it does not exist.You should create the property AND populate it.
Update
You should do this:
var source = from p in CommentsList
select new { p.Img, p.Name, p.Comment };
dt.Columns.Add("User");
dt.Columns.Add("Comment");
dt.Columns.Add("Img");
and then this:
DataRow userDetailsRow=dt.NewRow();
userDetailsRow["Img"] = item.Img;
userDetailsRow["User"] = item.Name;
Fix where it applies.
You need to add a Column in your DataTable with the name of Img before using this in DataBinding
userDetailsRow["User"] = item.Img;
should be
userDetailsRow["img"] = item.Img;

Categories